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,\
drawinglayer/source/primitive2d/metafileprimitive2d \
drawinglayer/source/primitive2d/modifiedcolorprimitive2d \
drawinglayer/source/primitive2d/objectinfoprimitive2d \
drawinglayer/source/primitive2d/pagehierarchyprimitive2d \
drawinglayer/source/primitive2d/pagepreviewprimitive2d \
drawinglayer/source/primitive2d/patternfillprimitive2d \
drawinglayer/source/primitive2d/pointarrayprimitive2d \
......
......@@ -367,6 +367,7 @@ namespace drawinglayer
case PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D: return OUString("PATTERNFILL");
case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D: return OUString("OBJECTINFO");
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);
}
}
......
/* -*- 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
ppm_Portable_Pixelmap \
psd_Adobe_Photoshop \
ras_Sun_Rasterfile \
svg_Scalable_Vector_Graphics_Draw \
svg_Scalable_Vector_Graphics \
svm_StarView_Metafile \
tga_Truevision_TARGA \
......@@ -721,6 +722,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_drawgraphics_f
PPM___Portable_Pixelmap \
PSD___Adobe_Photoshop \
RAS___Sun_Rasterfile \
SVG___Scalable_Vector_Graphics_Draw \
SVG___Scalable_Vector_Graphics \
SVM___StarView_Metafile \
TGA___Truevision_TARGA \
......@@ -761,6 +763,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impressgraphics_
png_Portable_Network_Graphic \
ppm_Portable_Pixelmap \
ras_Sun_Rasterfile \
svg_Scalable_Vector_Graphics_Draw \
svg_Scalable_Vector_Graphics \
svm_StarView_Metafile \
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 @@
<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="Preferred"><value>false</value></prop>
<prop oor:name="PreferredFilter"><value>SVG - Scalable Vector Graphics</value></prop>
<prop oor:name="UIName">
<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>
This diff is collapsed.
......@@ -266,9 +266,6 @@ private:
const Reference< XPropertySetInfo > & rxPropSetInfo );
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:
// XFilter
......
......@@ -102,6 +102,7 @@
#define PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 67)
#define PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D (PRIMITIVE2D_ID_RANGE_DRAWINGLAYER| 68)
#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
// 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
drawinglayer/source/primitive2d/texteffectprimitive2d.cxx
drawinglayer/source/primitive2d/textenumsprimitive2d.cxx
drawinglayer/source/primitive2d/texthierarchyprimitive2d.cxx
drawinglayer/source/primitive2d/pagehierarchyprimitive2d.cxx
drawinglayer/source/primitive2d/textlayoutdevice.cxx
drawinglayer/source/primitive2d/textlineprimitive2d.cxx
drawinglayer/source/primitive2d/textprimitive2d.cxx
......@@ -6281,6 +6282,7 @@ include/drawinglayer/primitive2d/textdecoratedprimitive2d.hxx
include/drawinglayer/primitive2d/texteffectprimitive2d.hxx
include/drawinglayer/primitive2d/textenumsprimitive2d.hxx
include/drawinglayer/primitive2d/texthierarchyprimitive2d.hxx
include/drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx
include/drawinglayer/primitive2d/textlayoutdevice.hxx
include/drawinglayer/primitive2d/textlineprimitive2d.hxx
include/drawinglayer/primitive2d/textprimitive2d.hxx
......
......@@ -38,6 +38,7 @@
#include <drawinglayer/primitive2d/patternfillprimitive2d.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <drawinglayer/primitive2d/maskprimitive2d.hxx>
#include <drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx>
namespace svgio
{
......@@ -1196,13 +1197,48 @@ namespace svgio
// #i124852# transform may be needed when userSpaceOnUse
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
rTarget.append(aSource);
const SvgNode* pParent(mrOwner.getParent());
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
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;
}
......
......@@ -26,6 +26,7 @@
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
#include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
#include <svgdocument.hxx>
namespace svgio
{
......@@ -670,21 +671,41 @@ namespace svgio
if(!aSequence.empty())
{
// 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));
// Another correction:
// If no Width/Height is set (usually done in
// <svg ... width="215.9mm" height="279.4mm" >) which
// is the case for own-Impress-exports, assume that
// the Units are alrteady 100ThMM.
// Maybe only for own-Impress-exports, thus may need to be
// &&ed with getDocument().findSvgNodeById("ooo:meta_slides"),
// but does not need to be.
bool bEmbedInFinalTransformPxTo100ThMM(true);
if(getDocument().findSvgNodeById("ooo:meta_slides")
&& !getWidth().isSet()
&& !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
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