31 #include <osl/diagnose.h>
41 struct PDFExtOutDevDataSync
43 enum Action{ CreateNamedDest,
56 BeginStructureElement,
58 SetCurrentStructureElement,
59 SetStructureAttribute,
60 SetStructureAttributeNumerical,
61 SetStructureBoundingBox,
73 struct PDFLinkDestination
85 std::deque< PDFExtOutDevDataSync::Action >
mActions;
107 mCurrentStructElement( 0 )
109 mStructParents.push_back( 0 );
110 mStructIdMap.push_back( 0 );
130 SAL_WARN_IF( nLinkId < 0,
"vcl",
"unmapped id in GlobalSyncData" );
143 SAL_WARN_IF( nStructId < 0,
"vcl",
"unmapped structure id in GlobalSyncData" );
154 case PDFExtOutDevDataSync::CreateNamedDest :
167 case PDFExtOutDevDataSync::CreateDest :
179 case PDFExtOutDevDataSync::CreateLink :
192 case PDFExtOutDevDataSync::CreateScreen:
203 case PDFExtOutDevDataSync::SetLinkDest :
210 case PDFExtOutDevDataSync::SetLinkURL :
217 case PDFExtOutDevDataSync::SetScreenURL:
224 case PDFExtOutDevDataSync::SetScreenStream:
231 case PDFExtOutDevDataSync::RegisterDest :
233 const sal_Int32 nDestId =
mParaInts.front();
236 "GlobalSyncData::PlayGlobalActions: DescribeRegisteredRequest has not been called for that destination!" );
246 case PDFExtOutDevDataSync::CreateOutlineItem :
254 case PDFExtOutDevDataSync::CreateNote :
265 case PDFExtOutDevDataSync::SetPageTransition :
273 case PDFExtOutDevDataSync::BeginStructureElement:
274 case PDFExtOutDevDataSync::EndStructureElement:
275 case PDFExtOutDevDataSync::SetCurrentStructureElement:
276 case PDFExtOutDevDataSync::SetStructureAttribute:
277 case PDFExtOutDevDataSync::SetStructureAttributeNumerical:
278 case PDFExtOutDevDataSync::SetStructureBoundingBox:
279 case PDFExtOutDevDataSync::SetActualText:
280 case PDFExtOutDevDataSync::SetAlternateText:
281 case PDFExtOutDevDataSync::CreateControl:
282 case PDFExtOutDevDataSync::BeginGroup:
283 case PDFExtOutDevDataSync::EndGroupGfxLink:
300 std::deque< std::shared_ptr< PDFWriter::AnyWidget > >
308 : mbGroupIgnoreGDIMtfActions ( false )
309 { mpGlobalData = pGlobal; }
318 SAL_WARN_IF( !pMtf,
"vcl",
"PageSyncData::PushAction -> no ConnectMetaFile !!!" );
320 PDFExtOutDevDataSync aSync;
325 aSync.nIdx = 0x7fffffff;
334 PDFExtOutDevDataSync aDataSync =
mActions.front();
336 switch( aDataSync.eAct )
338 case PDFExtOutDevDataSync::BeginStructureElement :
346 case PDFExtOutDevDataSync::EndStructureElement :
351 case PDFExtOutDevDataSync::SetCurrentStructureElement:
357 case PDFExtOutDevDataSync::SetStructureAttribute :
364 case PDFExtOutDevDataSync::SetStructureAttributeNumerical :
371 case PDFExtOutDevDataSync::SetStructureBoundingBox :
377 case PDFExtOutDevDataSync::SetActualText :
383 case PDFExtOutDevDataSync::SetAlternateText :
389 case PDFExtOutDevDataSync::CreateControl:
391 std::shared_ptr< PDFWriter::AnyWidget > pControl(
mControls.front() );
392 SAL_WARN_IF( !pControl,
"vcl",
"PageSyncData::PlaySyncPageAct: invalid widget!" );
398 case PDFExtOutDevDataSync::BeginGroup :
404 [](
const PDFExtOutDevDataSync& rAction) {
return rAction.eAct == PDFExtOutDevDataSync::EndGroupGfxLink; });
405 if ( isStartingGfxLink )
426 case PDFExtOutDevDataSync::EndGroupGfxLink :
432 sal_Int32 nTransparency =
mParaInts.front();
441 bool bClippingNeeded = ( aOutputRect != aVisibleOutputRect ) && !aVisibleOutputRect.
IsEmpty();
443 GfxLink aGfxLink( aGraphic.GetGfxLink() );
446 if ( bClippingNeeded )
457 AlphaMask aAlphaMask(aGraphic.GetSizePixel());
458 aAlphaMask.
Erase(nTransparency);
459 aMask = aAlphaMask.GetBitmap();
464 sal_uInt32 nBytes = aGfxLink.GetDataSize();
465 if( pData && nBytes )
474 if (rCurGDIMtfAction > 0)
485 auto ePixelFormat = aGraphic.GetBitmapEx().getPixelFormat();
489 if ( bClippingNeeded )
497 case PDFExtOutDevDataSync::CreateNamedDest:
498 case PDFExtOutDevDataSync::CreateDest:
499 case PDFExtOutDevDataSync::CreateLink:
500 case PDFExtOutDevDataSync::CreateScreen:
501 case PDFExtOutDevDataSync::SetLinkDest:
502 case PDFExtOutDevDataSync::SetLinkURL:
503 case PDFExtOutDevDataSync::SetScreenURL:
504 case PDFExtOutDevDataSync::SetScreenStream:
505 case PDFExtOutDevDataSync::RegisterDest:
506 case PDFExtOutDevDataSync::CreateOutlineItem:
507 case PDFExtOutDevDataSync::CreateNote:
508 case PDFExtOutDevDataSync::SetPageTransition:
522 mbTaggedPDF ( false ),
523 mbExportNotes ( true ),
524 mbExportNotesPages ( false ),
525 mbTransitionEffects ( true ),
526 mbUseLosslessCompression( true ),
527 mbReduceImageResolution ( false ),
528 mbExportFormFields ( false ),
529 mbExportBookmarks ( false ),
530 mbExportHiddenSlides ( false ),
531 mbSinglePageSheets ( false ),
532 mbExportNDests ( false ),
534 mnCompressionQuality ( 90 ),
613 return mpPageSyncData->PlaySyncPageAct( rWriter, rIdx, rMtf, *
this );
626 mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateNamedDest );
646 OSL_PRECOND( nDestId != -1,
"PDFExtOutDevData::DescribeRegisteredDest: invalid destination Id!" );
647 PDFLinkDestination aLinkDestination;
648 aLinkDestination.mRect = rRect;
650 aLinkDestination.mPageNr = nPageNr == -1 ?
mnPage : nPageNr;
651 aLinkDestination.mAreaType = eType;
703 mpGlobalSyncData->mActions.push_back(PDFExtOutDevDataSync::SetScreenStream);
714 mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateOutlineItem );
730 mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetPageTransition );
756 bool bSuccess =
false;
802 std::shared_ptr< PDFWriter::AnyWidget > pClone( rControlType.Clone() );
833 if (rOutputRect != rVisibleOutputRect)
848 StreamMode::READ | StreamMode::WRITE);
850 if (aDescriptor.Detect(
true) && aDescriptor.GetNumberOfImageComponents() == 4)
857 if ( aSize.
Width() < 32 &&
865 sal_Int32 nCurrentRatio = (100 * aSize.
Width() * aSize.
Height() * 4) /
868 static const struct {
872 { 100, 400 }, { 95, 700 }, { 90, 1000 }, { 85, 1200 },
873 { 80, 1500 }, { 75, 1700 }
875 sal_Int32 nTargetRatio = 10000;
876 bool bIsTargetRatioReached =
false;
877 for (
auto & rRatio : aRatios)
881 bIsTargetRatioReached =
true;
884 nTargetRatio = rRatio.mnRatio;
887 return ((nCurrentRatio > nTargetRatio) && bIsTargetRatioReached);
std::deque< PDFWriter::StructAttributeValue > mParaStructAttributeValues
void SetCurrentPageNumber(const sal_Int32 nPage)
std::deque< PDFWriter::StructAttribute > mParaStructAttributes
std::deque< PDFWriter::StructElement > mParaStructElements
void PushAction(const OutputDevice &rOutDev, const PDFExtOutDevDataSync::Action eAct)
bool mbGroupIgnoreGDIMtfActions
void SetIsExportNotes(const bool bExportNotes)
void SetPageTransition(PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr)
Sets the transitional effect to be applied when the current page gets shown.
void BeginGroup()
Start a new group of render output.
sal_Int32 RegisterDest()
registers a destination for which a destination ID needs to be known immediately, instead of later on...
std::deque< sal_Int32 > mParaInts
std::unique_ptr< ContentProperties > pData
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
bool PlaySyncPageAct(PDFWriter &rWriter, sal_uInt32 &rCurGDIMtfAction, const GDIMetaFile &rMtf)
bool SetCurrentStructureElement(sal_Int32 nElement)
set the current structure element
void SetScreenURL(sal_Int32 nScreenId, const OUString &rURL)
Set URL for a linked Screen annotation.
void SetAlternateText(const OUString &rText)
set the Alt attribute of a strutural element
sal_Int32 BeginStructureElement(enum StructElement eType, const OUString &rAlias)
begin a new logical structure element
std::deque< PDFWriter::DestAreaType > mParaDestAreaTypes
void SetStructureAttribute(PDFWriter::StructAttribute eAttr, PDFWriter::StructAttributeValue eVal)
set a structure attribute on the current structural element
void SetActualText(const OUString &rText)
set the ActualText attribute of a structural element
std::deque< sal_Int32 > mParaInts
const MapMode & GetMapMode() const
void SetIsReduceImageResolution(const bool bReduceImageResolution)
virtual ~PDFExtOutDevData() override
GDIMetaFile * GetConnectMetaFile() const
std::deque< tools::Rectangle > mParaRects
void SetIsExportNamedDestinations(const bool bExportNDests)
GfxLinkType
GfxLink graphic types that are supported by GfxLink.
const sal_uInt8 * GetData() const
std::vector< sal_Int32 > mStructParents
void SetStructureBoundingBox(const tools::Rectangle &rRect)
set the bounding box of a structural element
std::unique_ptr< GlobalSyncData > mpGlobalSyncData
constexpr tools::Long Width() const
bool GetIsLosslessCompression() const
void SetLinkPropertyID(sal_Int32 nLinkId, sal_Int32 nPropertyID)
Resolve link in logical structure.
std::deque< std::shared_ptr< PDFWriter::AnyWidget > > mControls
std::deque< sal_uInt32 > mParauInts
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void EndStructureElement()
end the current logical structure element
std::vector< sal_Int32 > mParaIds
sal_Int32 CreateNamedDest(const OUString &sDestName, const tools::Rectangle &rRect, sal_Int32 nPageNr, DestAreaType eType)
Create a new named destination to be used in a link from another PDF document.
void EndGroup(const Graphic &rGraphic, sal_uInt8 nTransparency, const tools::Rectangle &rOutputRect, const tools::Rectangle &rVisibleOutputRect)
End render output.
void SetLinkDest(sal_Int32 nLinkId, sal_Int32 nDestId)
Set the destination for a link.
PageSyncData(GlobalSyncData *pGlobal)
std::vector< OUString > maChapterNames
sal_Int32 GetCurrentStructureElement() const
get the current structure element id
void DrawJPGBitmap(SvStream &rJPGData, bool bIsTrueColor, const Size &rSrcSizePixel, const tools::Rectangle &rTargetArea, const Bitmap &rMask, const Graphic &rGraphic)
Insert a JPG encoded image (optionally with mask)
void SetIsExportFormFields(const bool bExportFormFields)
std::deque< Graphic > mGraphics
std::deque< OUString > mParaOUStrings
void SetAlternateText(const OUString &rText)
set the Alt attribute of a strutural element
std::deque< PDFExtOutDevDataSync::Action > mActions
void SetIsSinglePageSheets(const bool bSinglePageSheets)
void SetIsExportBookmarks(const bool bExportBookmarks)
void Erase(sal_uInt8 cTransparency)
PDFExtOutDevData(const OutputDevice &rOutDev)
void SetLinkDest(sal_Int32 nLinkId, sal_Int32 nDestId)
Set the destination for a link will change a URL type link to a dest link if necessary.
void PlayGlobalActions(PDFWriter &rWriter)
void SetCompressionQuality(const sal_Int32 nQuality)
void SetStructureAttributeNumerical(PDFWriter::StructAttribute eAttr, sal_Int32 nValue)
set a structure attribute on the current structural element
void SetIsExportNotesPages(const bool bExportNotesPages)
std::deque< PDFNote > mParaPDFNotes
void SetIsExportHiddenSlides(const bool bExportHiddenSlides)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
GlobalSyncData * mpGlobalData
bool mbUseLosslessCompression
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_Int32 CreateDest(const tools::Rectangle &rRect, sal_Int32 nPageNr=-1, PDFWriter::DestAreaType eType=PDFWriter::DestAreaType::XYZ)
Create a new destination to be used in a link.
void SetStructureAttributeNumerical(enum StructAttribute eAttr, sal_Int32 nValue)
set a structure attribute on the current structural element
std::deque< OUString > mParaOUStrings
void SetIsLosslessCompression(const bool bLosslessCompression)
void SetIsExportTaggedPDF(const bool bTaggedPDF)
void Push(PushFlags nFlags=PushFlags::ALL)
std::deque< PDFExtOutDevDataSync > mActions
void SetMapMode(const MapMode &rNewMapMode)
GfxLink GetGfxLink() const
sal_Int32 BeginStructureElement(PDFWriter::StructElement eType, const OUString &rAlias=OUString())
begin a new logical structure element
sal_Int32 CreateScreen(const tools::Rectangle &rRect, sal_Int32 nPageNr)
Create a Screen annotation.
sal_Int32 RegisterDestReference(sal_Int32 nDestId, const tools::Rectangle &rRect, sal_Int32 nPageNr, DestAreaType eType)
creates a destination which is not intended to be referred to by a link, but by a public destination ...
bool mbExportHiddenSlides
void DescribeRegisteredDest(sal_Int32 nDestId, const tools::Rectangle &rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType=PDFWriter::DestAreaType::XYZ)
provides detailed information about a destination range which previously has been registered using Re...
bool HasAdequateCompression(const Graphic &rGraphic, const tools::Rectangle &rOutputRect, const tools::Rectangle &rVisibleOutputRect) const
Detect if stream is compressed enough to avoid de-compress / scale & re-compress. ...
void SetLinkURL(sal_Int32 nLinkId, const OUString &rURL)
Set the URL for a link.
std::vector< sal_Int32 > mStructIdMap
void CreateNote(const tools::Rectangle &rRect, const PDFNote &rNote, sal_Int32 nPageNr=-1)
Create a new note on a page.
::std::map< sal_Int32, PDFLinkDestination > mFutureDestinations
sal_Int32 CreateControl(const AnyWidget &rControlType)
create a new form control
sal_Int32 CreateOutlineItem(sal_Int32 nParent, const OUString &rText, sal_Int32 nDestID)
Create a new outline item.
css::lang::Locale maDocLocale
std::unique_ptr< PageSyncData > mpPageSyncData
void PlayGlobalActions(PDFWriter &rWriter)
void SetStructureAttribute(enum StructAttribute eAttr, enum StructAttributeValue eVal)
set a structure attribute on the current structural element
sal_Int32 CreateLink(const tools::Rectangle &rRect, sal_Int32 nPageNr)
Create a new link on a page.
#define SAL_WARN_IF(condition, area, stream)
constexpr tools::Long Height() const
void SetScreenURL(sal_Int32 nScreenId, const OUString &rURL)
Sets the URL of a linked screen annotation.
GfxLinkType GetType() const
void SetLinkURL(sal_Int32 nLinkId, const OUString &rURL)
Set the URL for a link will change a dest type link to a URL type link if necessary.
sal_Int32 CreateNamedDest(const OUString &sDestName, const tools::Rectangle &rRect, sal_Int32 nPageNr=-1)
Create a new named destination to be used in a link to this document from another PDF document (see P...
sal_Int32 CreateLink(const tools::Rectangle &rRect, sal_Int32 nPageNr=-1)
Create a new link on a page.
bool PlaySyncPageAct(PDFWriter &rWriter, sal_uInt32 &rCurGDIMtfAction, const GDIMetaFile &rMtf, const PDFExtOutDevData &rOutDevData)
sal_Int32 mCurrentStructElement
bool mbReduceImageResolution
void SetDocumentLocale(const css::lang::Locale &rLoc)
std::deque< tools::Rectangle > mParaRects
sal_Int32 CreateOutlineItem(sal_Int32 nParent, const OUString &rText, sal_Int32 nDestID)
Create a new outline item.
sal_Int32 CreateDest(const tools::Rectangle &rRect, sal_Int32 nPageNr, DestAreaType eType)
Create a new destination to be used in a link.
void SetActualText(const OUString &rText)
set the ActualText attribute of a structural element
sal_uInt32 GetDataSize() const
void CreateNote(const tools::Rectangle &rRect, const PDFNote &rNote, sal_Int32 nPageNr)
Create a new note on a page.
const OutputDevice & mrOutDev
void SetIsExportTransitionEffects(const bool bTransitionalEffects)
sal_Int32 GetMappedStructId(sal_Int32)
const Graphic & GetCurrentGraphic() const
void CreateControl(const PDFWriter::AnyWidget &rControlType)
create a new form control
sal_Int32 CreateScreen(const tools::Rectangle &rRect, sal_Int32 nPageNr)
Creates a screen annotation.
void SetScreenStream(sal_Int32 nScreenId, const OUString &rURL)
Set URL for an embedded Screen annotation.
sal_Int32 mnCompressionQuality
void SetPageTransition(PDFWriter::PageTransition eType, sal_uInt32 nMilliSec)
Sets the transitional effect to be applied when the current page gets shown.
void SetScreenStream(sal_Int32 nScreenId, const OUString &rURL)
Sets the URL of an embedded screen annotation.
std::deque< MapMode > mParaMapModes
void SetStructureBoundingBox(const tools::Rectangle &rRect)
set the bounding box of a structural element
void EndStructureElement()
end a logical structure element
std::deque< PDFWriter::PageTransition > mParaPageTransitions
bool GetIsReduceImageResolution() const
void SetCurrentStructureElement(sal_Int32 nElement)
set the current structure element