Kaydet (Commit) 3087011e authored tarafından Armin Le Grand's avatar Armin Le Grand

Replace SVGFilter using SVGIO

Next step is to put more logic into the decision
if Draw or Impress should be loaded - if we have a
self-exported Impress, import as Impress, else
(including all not-self-created SVG Graphics) import
to Draw.
To do this it is necessary to be able to import to
different document formats at all. To do this, add
an internal filter type to the filter mechanism
(types/registration/...) and decide in the SVG
XExtendedFilterDetection::detect from SVGFilter
which one to use.
Added tooling for SVG detection and more, see
SVGFileInfo. This allows to detect for SVG, but
also if the creator was LO and if it was Draw or
Impress. The document format/filter is choosen
accordingly.
Corrected the error with <g visibility="hidden">
Slides inisde <g class="SlideGroup"> for import
of self-exported Impress documents. No idea why
this was written that way, but needs to be fixed
to get a visible content at all.
Also adapted the final mapping from pt to 100thmm
in SvgSvgNode::decomposeSvgNode. Unfortunately
(and also for unknown reasons) the self-exported
Impress does not write svg:width/height values,
thus the adaption from assumed svg-units (px) to
100thmm has to be skipped.
Have identified the place in svgio where I can
embed Pages/Slides to a helper-Primitive to later
be able to 'break' such GraphicObjects to multiple
Pages/Slides. I have added a Primitive called
PageHierarchyPrimitive2D for this purpose.

Change-Id: I38bfef6e7b16479a025fc754e38b4e21a006ad38
Reviewed-on: https://gerrit.libreoffice.org/55434Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
üst 4a0ca73c
...@@ -95,6 +95,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\ ...@@ -95,6 +95,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\
drawinglayer/source/primitive2d/metafileprimitive2d \ drawinglayer/source/primitive2d/metafileprimitive2d \
drawinglayer/source/primitive2d/modifiedcolorprimitive2d \ drawinglayer/source/primitive2d/modifiedcolorprimitive2d \
drawinglayer/source/primitive2d/objectinfoprimitive2d \ drawinglayer/source/primitive2d/objectinfoprimitive2d \
drawinglayer/source/primitive2d/pagehierarchyprimitive2d \
drawinglayer/source/primitive2d/pagepreviewprimitive2d \ drawinglayer/source/primitive2d/pagepreviewprimitive2d \
drawinglayer/source/primitive2d/patternfillprimitive2d \ drawinglayer/source/primitive2d/patternfillprimitive2d \
drawinglayer/source/primitive2d/pointarrayprimitive2d \ drawinglayer/source/primitive2d/pointarrayprimitive2d \
......
...@@ -367,6 +367,7 @@ namespace drawinglayer ...@@ -367,6 +367,7 @@ namespace drawinglayer
case PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D: return OUString("PATTERNFILL"); case PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D: return OUString("PATTERNFILL");
case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D: return OUString("OBJECTINFO"); case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D: return OUString("OBJECTINFO");
case PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D: return OUString("POLYPOLYGONSELECTION"); case PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D: return OUString("POLYPOLYGONSELECTION");
case PRIMITIVE2D_ID_PAGEHIERARCHYPRIMITIVE2D: return OUString("PAGEHIERARCHY");
default: return OUString::number((nId >> 16) & 0xFF) + "|" + OUString::number(nId & 0xFF); default: return OUString::number((nId >> 16) & 0xFF) + "|" + OUString::number(nId & 0xFF);
} }
} }
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx>
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
using namespace com::sun::star;
namespace drawinglayer
{
namespace primitive2d
{
PageHierarchyPrimitive2D::PageHierarchyPrimitive2D(const Primitive2DContainer& rChildren)
: GroupPrimitive2D(rChildren)
{
}
// provide unique ID
ImplPrimitive2DIDBlock(PageHierarchyPrimitive2D, PRIMITIVE2D_ID_PAGEHIERARCHYPRIMITIVE2D)
} // end of namespace primitive2d
} // end of namespace drawinglayer
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -695,6 +695,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_drawgraphics_typ ...@@ -695,6 +695,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_drawgraphics_typ
ppm_Portable_Pixelmap \ ppm_Portable_Pixelmap \
psd_Adobe_Photoshop \ psd_Adobe_Photoshop \
ras_Sun_Rasterfile \ ras_Sun_Rasterfile \
svg_Scalable_Vector_Graphics_Draw \
svg_Scalable_Vector_Graphics \ svg_Scalable_Vector_Graphics \
svm_StarView_Metafile \ svm_StarView_Metafile \
tga_Truevision_TARGA \ tga_Truevision_TARGA \
...@@ -721,6 +722,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_drawgraphics_f ...@@ -721,6 +722,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_drawgraphics_f
PPM___Portable_Pixelmap \ PPM___Portable_Pixelmap \
PSD___Adobe_Photoshop \ PSD___Adobe_Photoshop \
RAS___Sun_Rasterfile \ RAS___Sun_Rasterfile \
SVG___Scalable_Vector_Graphics_Draw \
SVG___Scalable_Vector_Graphics \ SVG___Scalable_Vector_Graphics \
SVM___StarView_Metafile \ SVM___StarView_Metafile \
TGA___Truevision_TARGA \ TGA___Truevision_TARGA \
...@@ -761,6 +763,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impressgraphics_ ...@@ -761,6 +763,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impressgraphics_
png_Portable_Network_Graphic \ png_Portable_Network_Graphic \
ppm_Portable_Pixelmap \ ppm_Portable_Pixelmap \
ras_Sun_Rasterfile \ ras_Sun_Rasterfile \
svg_Scalable_Vector_Graphics_Draw \
svg_Scalable_Vector_Graphics \ svg_Scalable_Vector_Graphics \
svm_StarView_Metafile \ svm_StarView_Metafile \
tif_Tag_Image_File \ tif_Tag_Image_File \
......
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="SVG - Scalable Vector Graphics Draw" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"><value>com.sun.star.comp.Draw.SVGFilter</value></prop>
<prop oor:name="UserData"><value></value></prop>
<prop oor:name="UIName">
<value xml:lang="en-US">SVG - Scalable Vector Graphics Draw</value>
</prop>
<prop oor:name="FileFormatVersion"><value>0</value></prop>
<prop oor:name="Type"><value>svg_Scalable_Vector_Graphics_Draw</value></prop>
<prop oor:name="TemplateName"/>
<prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop>
</node>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>svg svgz</value></prop> <prop oor:name="Extensions"><value>svg svgz</value></prop>
<prop oor:name="MediaType"><value>image/svg+xml</value></prop> <prop oor:name="MediaType"><value>image/svg+xml</value></prop>
<prop oor:name="Preferred"><value>true</value></prop> <prop oor:name="Preferred"><value>false</value></prop>
<prop oor:name="PreferredFilter"><value>SVG - Scalable Vector Graphics</value></prop> <prop oor:name="PreferredFilter"><value>SVG - Scalable Vector Graphics</value></prop>
<prop oor:name="UIName"> <prop oor:name="UIName">
<value>SVG - Scalable Vector Graphics</value> <value>SVG - Scalable Vector Graphics</value>
......
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<node oor:name="svg_Scalable_Vector_Graphics_Draw" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.Draw.SVGFilter</value></prop>
<prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>svg svgz</value></prop>
<prop oor:name="MediaType"><value>image/svg+xml</value></prop>
<prop oor:name="Preferred"><value>true</value></prop>
<prop oor:name="PreferredFilter"><value>SVG - Scalable Vector Graphics Draw</value></prop>
<prop oor:name="UIName">
<value>SVG - Scalable Vector Graphics Draw</value>
</prop>
<prop oor:name="ClipboardFormat"/>
</node>
...@@ -64,6 +64,7 @@ using namespace ::com::sun::star; ...@@ -64,6 +64,7 @@ using namespace ::com::sun::star;
namespace namespace
{ {
static const char constFilterNameDraw[] = "svg_Scalable_Vector_Graphics_Draw";
static const char constFilterName[] = "svg_Scalable_Vector_Graphics"; static const char constFilterName[] = "svg_Scalable_Vector_Graphics";
} }
...@@ -254,19 +255,22 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto ...@@ -254,19 +255,22 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto
// pTargetSdrPage->SetBorder(...) and // pTargetSdrPage->SetBorder(...) and
// pTargetSdrPage->SetSize(...), // pTargetSdrPage->SetSize(...),
// but ::adaptSizeAndBorderForAllPages // but ::adaptSizeAndBorderForAllPages
// Do use original Size and borders to get as close to original
// as possible for better turn-arounds.
pTargetSdrPage->getSdrModelFromSdrPage().adaptSizeAndBorderForAllPages( pTargetSdrPage->getSdrModelFromSdrPage().adaptSizeAndBorderForAllPages(
Size( Size(
aGraphicSize.Width() + nAllBorder + nAllBorder, aGraphicSize.Width(),
aGraphicSize.Height() + nAllBorder + nAllBorder), aGraphicSize.Height()),
nAllBorder, nAllBorder,
nAllBorder, nAllBorder,
nAllBorder, nAllBorder,
nAllBorder); nAllBorder);
// set pos/size at SdrGraphicObj - add offset to PageBorder // set pos/size at SdrGraphicObj - use zero position for
// better turn-around results
aNewSdrGrafObj->SetSnapRect( aNewSdrGrafObj->SetSnapRect(
tools::Rectangle( tools::Rectangle(
Point(nAllBorder, nAllBorder), Point(0, 0),
aGraphicSize)); aGraphicSize));
// insert to page (owner change of SdrGrafObj) // insert to page (owner change of SdrGrafObj)
...@@ -472,86 +476,220 @@ void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc ...@@ -472,86 +476,220 @@ void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc
mxDstDoc = xDoc; mxDstDoc = xDoc;
} }
bool SVGFilter::isStreamGZip(const uno::Reference<io::XInputStream>& xInput) // There is already another SVG-Type_Detector, see
// vcl/source/filter/graphicfilter.cxx ("DOCTYPE svg"),
// but since these start from different preconditions it is not
// easy to unify these. For now, use this local helper.
class SVGFileInfo
{ {
uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY); private:
if(xSeek.is()) const uno::Reference<io::XInputStream>& mxInput;
xSeek->seek(0); uno::Sequence< sal_Int8 > mnFirstBytes;
sal_Int32 mnFirstBytesSize;
uno::Sequence<sal_Int8> aBuffer(2); sal_uInt64 mnFirstRead;
const sal_uInt64 nBytes = xInput->readBytes(aBuffer, 2); bool mbProcessed;
if (nBytes == 2) bool mbIsSVG;
bool impCheckForMagic(
const sal_Int8* pMagic,
const sal_Int32 nMagicSize)
{ {
const sal_Int8* pBuffer = aBuffer.getConstArray(); const sal_Int8* pBuffer(mnFirstBytes.getConstArray());
if (pBuffer[0] == 0x1F && static_cast<sal_uInt8>(pBuffer[1]) == 0x8B) return std::search(
return true; pBuffer,
pBuffer + mnFirstRead,
pMagic,
pMagic + nMagicSize) != pBuffer + mnFirstRead;
} }
return false;
}
bool SVGFilter::isStreamSvg(const uno::Reference<io::XInputStream>& xInput) void impEnsureProcessed()
{ {
uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY); if(mbProcessed)
if(xSeek.is()) {
xSeek->seek(0); return;
}
const sal_Int32 nLookAhead = 1024; mbProcessed = true;
uno::Sequence<sal_Int8> aBuffer(nLookAhead);
const sal_uInt64 nBytes = xInput->readBytes(aBuffer, nLookAhead);
const sal_Int8* pBuffer = aBuffer.getConstArray();
sal_Int8 aMagic1[] = {'<', 's', 'v', 'g'}; if(!mxInput.is())
sal_Int32 const aMagic1Size = SAL_N_ELEMENTS(aMagic1); {
return;
}
if (std::search(pBuffer, pBuffer + nBytes, aMagic1, aMagic1 + aMagic1Size) != pBuffer + nBytes ) if(0 == mnFirstBytesSize)
return true; {
return;
}
sal_Int8 aMagic2[] = {'D', 'O', 'C', 'T', 'Y', 'P', 'E', ' ', 's', 'v', 'g'}; mnFirstBytes.realloc(mnFirstBytesSize);
sal_Int32 const aMagic2Size = SAL_N_ELEMENTS(aMagic2);
return std::search(pBuffer, pBuffer + nBytes, aMagic2, aMagic2 + aMagic2Size) != pBuffer + nBytes; if(mnFirstBytesSize != mnFirstBytes.getLength())
} {
return;
}
OUString SAL_CALL SVGFilter::detect(Sequence<PropertyValue>& rDescriptor) std::unique_ptr< SvStream > aStream(utl::UcbStreamHelper::CreateStream(mxInput, true));
{
utl::MediaDescriptor aMediaDescriptor(rDescriptor);
uno::Reference<io::XInputStream> xInput(aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
if (!xInput.is()) if(!aStream.get())
return OUString(); {
return;
}
const sal_uLong nStreamPos(aStream->Tell());
aStream->Seek(STREAM_SEEK_TO_END);
const sal_uLong nStreamLen(aStream->Tell() - nStreamPos);
aStream->Seek(nStreamPos);
try { if(aStream->GetError())
if (isStreamGZip(xInput))
{ {
std::unique_ptr<SvStream> aStream(utl::UcbStreamHelper::CreateStream(xInput, true )); return;
if(!aStream.get()) }
return OUString();
mnFirstRead = aStream->ReadBytes(
&mnFirstBytes[0],
std::min(nStreamLen, sal_uLong(mnFirstBytesSize)));
SvStream* pMemoryStream = new SvMemoryStream; if(aStream->GetError())
uno::Reference<io::XSeekable> xSeek(xInput, uno::UNO_QUERY); {
if (!xSeek.is()) return;
return OUString(); }
xSeek->seek(0);
// check if it is gzipped -> svgz
if(mnFirstBytes[0] == 0x1F && static_cast<sal_uInt8>(mnFirstBytes[1]) == 0x8B)
{
ZCodec aCodec; ZCodec aCodec;
aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
aCodec.Decompress(*aStream.get(), *pMemoryStream); aCodec.BeginCompression(
ZCODEC_DEFAULT_COMPRESSION,
false,
true);
mnFirstRead = aCodec.Read(
*aStream,
reinterpret_cast< sal_uInt8* >(mnFirstBytes.getArray()),
mnFirstBytesSize);
aCodec.EndCompression(); aCodec.EndCompression();
pMemoryStream->Seek(STREAM_SEEK_TO_BEGIN); }
uno::Reference<io::XInputStream> xDecompressedInput(new utl::OSeekableInputStreamWrapper(pMemoryStream, true));
if(!mbIsSVG)
{
const sal_Int8 aMagic[] = {'<', 's', 'v', 'g'};
const sal_Int32 nMagicSize(SAL_N_ELEMENTS(aMagic));
if (xDecompressedInput.is() && isStreamSvg(xDecompressedInput)) mbIsSVG = impCheckForMagic(aMagic, nMagicSize);
return OUString(constFilterName);
} }
else
if(!mbIsSVG)
{ {
if (isStreamSvg(xInput)) const sal_Int8 aMagic[] = {'D', 'O', 'C', 'T', 'Y', 'P', 'E', ' ', 's', 'v', 'g'};
return OUString(constFilterName); const sal_Int32 nMagicSize(SAL_N_ELEMENTS(aMagic));
mbIsSVG = impCheckForMagic(aMagic, nMagicSize);
} }
} catch (css::io::IOException & e) {
return;
}
public:
SVGFileInfo(
const uno::Reference<io::XInputStream>& xInput,
sal_Int32 nFirstBytesSize = 4096)
: mxInput(xInput),
mnFirstBytes(),
mnFirstBytesSize(nFirstBytesSize),
mnFirstRead(0),
mbProcessed(false),
mbIsSVG(false)
{
// For the default buffer size: Use not too big
// (not more than 16K), but also not too small
// (not less than 1/2K), see comments at
// ImpPeekGraphicFormat, SVG section.
// I remember these cases and it *can* happen
// that SVGs have quite massive comments in their
// headings (!)
// Limit to plausible sizes, also for security reasons
mnFirstBytesSize = std::min(sal_Int32(512), mnFirstBytesSize);
mnFirstBytesSize = std::max(sal_Int32(16384), mnFirstBytesSize);
}
bool isSVG()
{
impEnsureProcessed();
return mbIsSVG;
}
bool isOwnFormat()
{
impEnsureProcessed();
if(mbIsSVG)
{
// xmlns:ooo
const sal_Int8 aMagic[] = {'x', 'm', 'l', 'n', 's', ':', 'o', 'o', 'o'};
const sal_Int32 nMagicSize(SAL_N_ELEMENTS(aMagic));
return impCheckForMagic(aMagic, nMagicSize);
}
return false;
}
bool isImpress()
{
impEnsureProcessed();
if(mbIsSVG)
{
// ooo:meta_slides
const sal_Int8 aMagic[] = {'o', 'o', 'o', ':', 'm', 'e', 't', 'a', '_', 's', 'l', 'i', 'd', 'e', 's'};
const sal_Int32 nMagicSize(SAL_N_ELEMENTS(aMagic));
return impCheckForMagic(aMagic, nMagicSize);
}
return false;
}
};
OUString SAL_CALL SVGFilter::detect(Sequence<PropertyValue>& rDescriptor)
{
utl::MediaDescriptor aMediaDescriptor(rDescriptor);
uno::Reference<io::XInputStream> xInput(aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
OUString aRetval;
if (!xInput.is())
{
return aRetval;
}
try
{
SVGFileInfo aSVGFileInfo(xInput, 2048);
if(aSVGFileInfo.isSVG())
{
// We have SVG - set default document format to Draw
aRetval = OUString(constFilterNameDraw);
if(aSVGFileInfo.isOwnFormat())
{
// it's a file that was written/exported by LO
if(aSVGFileInfo.isImpress())
{
// it was written by Impress export. Set document
// format for import to Impress
aRetval = OUString(constFilterName);
}
}
}
}
catch (css::io::IOException & e)
{
SAL_WARN("filter.svg", "caught " << e); SAL_WARN("filter.svg", "caught " << e);
} }
return OUString();
return aRetval;
} }
#define SVG_FILTER_IMPL_NAME "com.sun.star.comp.Draw.SVGFilter" #define SVG_FILTER_IMPL_NAME "com.sun.star.comp.Draw.SVGFilter"
......
...@@ -266,9 +266,6 @@ private: ...@@ -266,9 +266,6 @@ private:
const Reference< XPropertySetInfo > & rxPropSetInfo ); const Reference< XPropertySetInfo > & rxPropSetInfo );
DECL_LINK( CalcFieldHdl, EditFieldInfo*, void ); DECL_LINK( CalcFieldHdl, EditFieldInfo*, void );
static bool isStreamGZip(const css::uno::Reference<css::io::XInputStream>& xInput);
static bool isStreamSvg(const css::uno::Reference<css::io::XInputStream>& xInput);
protected: protected:
// XFilter // XFilter
......
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
#define PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 67) #define PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 67)
#define PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 68) #define PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 68)
#define PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 69) #define PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 69)
#define PRIMITIVE2D_ID_PAGEHIERARCHYPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 70)
// When you add a new primitive, please update the drawinglayer::primitive2d::idToString() function // When you add a new primitive, please update the drawinglayer::primitive2d::idToString() function
// in drawinglayer/source/primitive2d/baseprimitive2d.cxx. // in drawinglayer/source/primitive2d/baseprimitive2d.cxx.
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_PAGEHIERARCHYPRIMITIVE2D_HXX
#define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_PAGEHIERARCHYPRIMITIVE2D_HXX
#include <drawinglayer/drawinglayerdllapi.h>
#include <drawinglayer/primitive2d/groupprimitive2d.hxx>
#include <rtl/ustring.hxx>
namespace drawinglayer
{
namespace primitive2d
{
/** PageHierarchyPrimitive2D class
This primitive encapsulates text lines.
*/
class DRAWINGLAYER_DLLPUBLIC PageHierarchyPrimitive2D : public GroupPrimitive2D
{
private:
public:
/// constructor
explicit PageHierarchyPrimitive2D(const Primitive2DContainer& rChildren);
/// provide unique ID
DeclPrimitive2DIDBlock()
};
} // end of namespace primitive2d
} // end of namespace drawinglayer
#endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_PAGEHIERARCHYPRIMITIVE2D_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -3941,6 +3941,7 @@ drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx ...@@ -3941,6 +3941,7 @@ drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx
drawinglayer/source/primitive2d/texteffectprimitive2d.cxx drawinglayer/source/primitive2d/texteffectprimitive2d.cxx
drawinglayer/source/primitive2d/textenumsprimitive2d.cxx drawinglayer/source/primitive2d/textenumsprimitive2d.cxx
drawinglayer/source/primitive2d/texthierarchyprimitive2d.cxx drawinglayer/source/primitive2d/texthierarchyprimitive2d.cxx
drawinglayer/source/primitive2d/pagehierarchyprimitive2d.cxx
drawinglayer/source/primitive2d/textlayoutdevice.cxx drawinglayer/source/primitive2d/textlayoutdevice.cxx
drawinglayer/source/primitive2d/textlineprimitive2d.cxx drawinglayer/source/primitive2d/textlineprimitive2d.cxx
drawinglayer/source/primitive2d/textprimitive2d.cxx drawinglayer/source/primitive2d/textprimitive2d.cxx
...@@ -6281,6 +6282,7 @@ include/drawinglayer/primitive2d/textdecoratedprimitive2d.hxx ...@@ -6281,6 +6282,7 @@ include/drawinglayer/primitive2d/textdecoratedprimitive2d.hxx
include/drawinglayer/primitive2d/texteffectprimitive2d.hxx include/drawinglayer/primitive2d/texteffectprimitive2d.hxx
include/drawinglayer/primitive2d/textenumsprimitive2d.hxx include/drawinglayer/primitive2d/textenumsprimitive2d.hxx
include/drawinglayer/primitive2d/texthierarchyprimitive2d.hxx include/drawinglayer/primitive2d/texthierarchyprimitive2d.hxx
include/drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx
include/drawinglayer/primitive2d/textlayoutdevice.hxx include/drawinglayer/primitive2d/textlayoutdevice.hxx
include/drawinglayer/primitive2d/textlineprimitive2d.hxx include/drawinglayer/primitive2d/textlineprimitive2d.hxx
include/drawinglayer/primitive2d/textprimitive2d.hxx include/drawinglayer/primitive2d/textprimitive2d.hxx
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <drawinglayer/primitive2d/patternfillprimitive2d.hxx> #include <drawinglayer/primitive2d/patternfillprimitive2d.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx> #include <basegfx/polygon/b2dpolygontools.hxx>
#include <drawinglayer/primitive2d/maskprimitive2d.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
#include <drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx>
namespace svgio namespace svgio
{ {
...@@ -1196,13 +1197,48 @@ namespace svgio ...@@ -1196,13 +1197,48 @@ namespace svgio
// #i124852# transform may be needed when userSpaceOnUse // #i124852# transform may be needed when userSpaceOnUse
pMask->apply(aSource, pTransform); pMask->apply(aSource, pTransform);
} }
}
// This is part of the SVG import of self-written SVGs from
// Draw/Impress containing multiple Slides/Pages. To be able
// to later 'break' these to multiple Pages if wanted, embed
// each Page-Content in a identifiable Primitive Grouping
// Object.
// This is the case when the current Node is a GroupNode, has
// class="Page" set, has a parent that also is a GroupNode
// at which class="Slide" is set.
// Multiple Slides/Pages are possible for Draw and Impress.
if(SVGTokenG == mrOwner.getType() && mrOwner.getClass())
{
const OUString aOwnerClass(*mrOwner.getClass());
if(!aSource.empty()) // test again, applied mask may have lead to empty geometry if("Page" == aOwnerClass)
{ {
// append to current target const SvgNode* pParent(mrOwner.getParent());
rTarget.append(aSource);
if(nullptr != pParent && SVGTokenG == pParent->getType() && pParent->getClass())
{
const OUString aParentClass(*pParent->getClass());
if("Slide" == aParentClass)
{
// embed to grouping primitive to identify the
// Slide/Page information
const drawinglayer::primitive2d::Primitive2DReference xRef(
new drawinglayer::primitive2d::PageHierarchyPrimitive2D(
aSource));
aSource = drawinglayer::primitive2d::Primitive2DContainer { xRef };
}
}
} }
} }
if(!aSource.empty()) // test again, applied mask may have lead to empty geometry
{
// append to current target
rTarget.append(aSource);
}
} }
} }
...@@ -2216,6 +2252,36 @@ namespace svgio ...@@ -2216,6 +2252,36 @@ namespace svgio
return Visibility_visible; return Visibility_visible;
} }
// Visibility correction/exception for self-exported SVGs:
// When Impress exports single or multi-page SVGs, it puts the
// single slides into <g visibility="hidden">. Not sure why
// whis happens, but this leads (correctly) to empty imported
// Graphics.
// Thus, if Visibility_hidden is active and owner is a SVGTokenG
// and it's parent is also a SVGTokenG and it has a Class 'SlideGroup'
// set, check if we are an Impress export.
// We are an Impress export if an SVG-Node titled 'ooo:meta_slides'
// exists.
// All togehter gives:
if(Visibility_hidden == maVisibility
&& SVGTokenG == mrOwner.getType()
&& nullptr != mrOwner.getDocument().findSvgNodeById("ooo:meta_slides"))
{
const SvgNode* pParent(mrOwner.getParent());
if(nullptr != pParent && SVGTokenG == pParent->getType() && pParent->getClass())
{
const OUString aClass(*pParent->getClass());
if("SlideGroup" == aClass)
{
// if we detect this exception,
// ovverride Visibility_hidden -> Visibility_visible
return Visibility_visible;
}
}
}
return maVisibility; return maVisibility;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <drawinglayer/primitive2d/polygonprimitive2d.hxx> #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
#include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx> #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
#include <svgdocument.hxx>
namespace svgio namespace svgio
{ {
...@@ -670,21 +671,41 @@ namespace svgio ...@@ -670,21 +671,41 @@ namespace svgio
if(!aSequence.empty()) if(!aSequence.empty())
{ {
// embed in transform primitive to scale to 1/100th mm // Another correction:
// where 1 inch == 25.4 mm to get from Svg coordinates (px) to // If no Width/Height is set (usually done in
// drawinglayer coordinates // <svg ... width="215.9mm" height="279.4mm" >) which
const double fScaleTo100thmm(25.4 * 100.0 / F_SVG_PIXEL_PER_INCH); // is the case for own-Impress-exports, assume that
const basegfx::B2DHomMatrix aTransform( // the Units are alrteady 100ThMM.
basegfx::utils::createScaleB2DHomMatrix( // Maybe only for own-Impress-exports, thus may need to be
fScaleTo100thmm, // &&ed with getDocument().findSvgNodeById("ooo:meta_slides"),
fScaleTo100thmm)); // but does not need to be.
bool bEmbedInFinalTransformPxTo100ThMM(true);
const drawinglayer::primitive2d::Primitive2DReference xTransform(
new drawinglayer::primitive2d::TransformPrimitive2D( if(getDocument().findSvgNodeById("ooo:meta_slides")
aTransform, && !getWidth().isSet()
aSequence)); && !getHeight().isSet())
{
bEmbedInFinalTransformPxTo100ThMM = false;
}
if(bEmbedInFinalTransformPxTo100ThMM)
{
// embed in transform primitive to scale to 1/100th mm
// where 1 inch == 25.4 mm to get from Svg coordinates (px) to
// drawinglayer coordinates
const double fScaleTo100thmm(25.4 * 100.0 / F_SVG_PIXEL_PER_INCH);
const basegfx::B2DHomMatrix aTransform(
basegfx::utils::createScaleB2DHomMatrix(
fScaleTo100thmm,
fScaleTo100thmm));
const drawinglayer::primitive2d::Primitive2DReference xTransform(
new drawinglayer::primitive2d::TransformPrimitive2D(
aTransform,
aSequence));
aSequence = drawinglayer::primitive2d::Primitive2DContainer { xTransform }; aSequence = drawinglayer::primitive2d::Primitive2DContainer { xTransform };
}
// append to result // append to result
rTarget.append(aSequence); rTarget.append(aSequence);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment