summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2023-06-05 11:49:41 +0200
committerAndras Timar <andras.timar@collabora.com>2023-06-08 21:53:59 +0200
commit53d610786ba8085fcce331174c74294c90c41a20 (patch)
tree3f4af2f6ebc0a22b5070a0a951d79f6221309fa9 /sd
parent260bc16e1923016d0628a8779e219b290d4c9011 (diff)
pdfium: better suport for annotations and some fixes
Added suport to import FreeText annotations. Added some suport to export graphical annotations. Fixed some color issues to be more inline with the pdfium library. Change-Id: I7371595ebb95594ee765ae532ca7c7d4f0499592 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152606 Tested-by: Jenkins Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/inc/Annotation.hxx5
-rw-r--r--sd/source/core/annotations/Annotation.cxx12
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx5
-rw-r--r--sd/source/ui/annotations/annotationtag.cxx23
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx17
5 files changed, 49 insertions, 13 deletions
diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx
index 707f2cdc8e78..00870dc703e8 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -133,6 +133,10 @@ public:
return bool(m_pCustomAnnotationMarker);
}
+ void setIsFreeText(bool value) { m_bIsFreeText = value; }
+
+ bool isFreeText() const { return m_bIsFreeText; }
+
private:
// destructor is private and will be called indirectly by the release call virtual ~Annotation() {}
@@ -152,6 +156,7 @@ private:
rtl::Reference<TextApiObject> m_TextRange;
std::unique_ptr<CustomAnnotationMarker> m_pCustomAnnotationMarker;
+ bool m_bIsFreeText;
};
}
diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx
index 850f1a973ff1..432d38f9cb32 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -117,11 +117,13 @@ void createAnnotation(uno::Reference<office::XAnnotation>& xAnnotation, SdPage*
sal_uInt32 Annotation::m_nLastId = 1;
-Annotation::Annotation( const uno::Reference<uno::XComponentContext>& context, SdPage* pPage )
-: ::cppu::WeakComponentImplHelper<office::XAnnotation>(m_aMutex)
-, ::cppu::PropertySetMixin<office::XAnnotation>(context, IMPLEMENTS_PROPERTY_SET, uno::Sequence<OUString>())
-, m_nId( m_nLastId++ )
-, mpPage( pPage )
+Annotation::Annotation(const uno::Reference<uno::XComponentContext>& context, SdPage* pPage)
+ : ::cppu::WeakComponentImplHelper<office::XAnnotation>(m_aMutex)
+ , ::cppu::PropertySetMixin<office::XAnnotation>(context, IMPLEMENTS_PROPERTY_SET,
+ uno::Sequence<OUString>())
+ , m_nId(m_nLastId++)
+ , mpPage(pPage)
+ , m_bIsFreeText(false)
{
}
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 39c6ada55f4e..35b1bffbcb73 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -189,6 +189,11 @@ bool SdPdfFilter::Import()
rCustomAnnotationMarker.maFillColor = COL_TRANSPARENT;
}
}
+ else if (rPDFAnnotation.meSubType == vcl::pdf::PDFAnnotationSubType::FreeText)
+ {
+ auto* pAnnotation = static_cast<sd::Annotation*>(xAnnotation.get());
+ pAnnotation->setIsFreeText(true);
+ }
}
}
mrDocument.setLock(bWasLocked);
diff --git a/sd/source/ui/annotations/annotationtag.cxx b/sd/source/ui/annotations/annotationtag.cxx
index 7afe26ee54b0..dbadf4cb6fe1 100644
--- a/sd/source/ui/annotations/annotationtag.cxx
+++ b/sd/source/ui/annotations/annotationtag.cxx
@@ -524,18 +524,29 @@ BitmapEx AnnotationTag::CreateAnnotationBitmap( bool bSelected )
{
ScopedVclPtrInstance< VirtualDevice > pVDev;
- OUString sInitials(mxAnnotation->getInitials());
- if (sInitials.isEmpty())
- sInitials = getInitials(mxAnnotation->getAuthor());
+ OUString sText;
+ auto* pAnnotation = dynamic_cast<sd::Annotation*>(mxAnnotation.get());
+ if (pAnnotation && pAnnotation->isFreeText())
+ {
+ sText = mxAnnotation->getTextRange()->getString();
+ }
+ else
+ {
+ OUString sInitials(mxAnnotation->getInitials());
+ if (sInitials.isEmpty())
+ {
+ sInitials = getInitials(mxAnnotation->getAuthor());
+ }
- OUString sAuthor(sInitials + " " + OUString::number(mnIndex));
+ sText = sInitials + " " + OUString::number(mnIndex);
+ }
pVDev->SetFont( mrFont );
const int BORDER_X = 4; // pixels
const int BORDER_Y = 4; // pixels
- maSize = Size( pVDev->GetTextWidth( sAuthor ) + 2*BORDER_X, pVDev->GetTextHeight() + 2*BORDER_Y );
+ maSize = Size(pVDev->GetTextWidth(sText) + 2 * BORDER_X, pVDev->GetTextHeight() + 2 * BORDER_Y);
pVDev->SetOutputSizePixel( maSize, false );
Color aBorderColor( maColor );
@@ -563,7 +574,7 @@ BitmapEx AnnotationTag::CreateAnnotationBitmap( bool bSelected )
pVDev->DrawRect( aBorderRect );
pVDev->SetTextColor( maColor.IsDark() ? COL_WHITE : COL_BLACK );
- pVDev->DrawText( Point( BORDER_X, BORDER_Y ), sAuthor );
+ pVDev->DrawText(Point(BORDER_X, BORDER_Y), sText);
return pVDev->GetBitmapEx( aPos, maSize );
}
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 3ff5fd0de266..dd2c897b4930 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -1597,15 +1597,28 @@ static void ImplPDFExportComments( const uno::Reference< drawing::XDrawPage >& x
uno::Reference< office::XAnnotation > xAnnotation( xAnnotationEnumeration->nextElement() );
geometry::RealPoint2D aRealPoint2D( xAnnotation->getPosition() );
+ geometry::RealSize2D aRealSize2D(xAnnotation->getSize());
uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
vcl::PDFNote aNote;
aNote.Title = xAnnotation->getAuthor();
aNote.Contents = xText->getString();
aNote.maModificationDate = xAnnotation->getDateTime();
+ auto* pAnnotation = dynamic_cast<sd::Annotation*>(xAnnotation.get());
+ aNote.isFreeText = pAnnotation && pAnnotation->isFreeText();
+ if (pAnnotation && pAnnotation->hasCustomAnnotationMarker())
+ {
+ aNote.maPolygons = pAnnotation->getCustomAnnotationMarker().maPolygons;
+ aNote.annotColor = pAnnotation->getCustomAnnotationMarker().maLineColor;
+ aNote.interiorColor = pAnnotation->getCustomAnnotationMarker().maFillColor;
+ }
- rPDFExtOutDevData.CreateNote( ::tools::Rectangle( Point( static_cast< ::tools::Long >( aRealPoint2D.X * 100 ),
- static_cast< ::tools::Long >( aRealPoint2D.Y * 100 ) ), Size( 1000, 1000 ) ), aNote );
+ rPDFExtOutDevData.CreateNote(
+ ::tools::Rectangle(Point(static_cast<::tools::Long>(aRealPoint2D.X * 100),
+ static_cast<::tools::Long>(aRealPoint2D.Y * 100)),
+ Size(static_cast<::tools::Long>(aRealSize2D.Width * 100),
+ static_cast<::tools::Long>(aRealSize2D.Height * 100))),
+ aNote);
}
}
catch (const uno::Exception&)