[Libreoffice-commits] core.git: svgio/inc svgio/source

Armin Le Grand alg at apache.org
Tue Jun 18 05:21:48 PDT 2013


 svgio/inc/svgio/svgreader/svgstyleattributes.hxx |   18 +++++
 svgio/inc/svgio/svgreader/svgtoken.hxx           |    1 
 svgio/source/svgreader/svgcharacternode.cxx      |   32 +++++++++
 svgio/source/svgreader/svgdocumenthandler.cxx    |   22 ++++++
 svgio/source/svgreader/svgnode.cxx               |    2 
 svgio/source/svgreader/svgstyleattributes.cxx    |   77 +++++++++++++++++++++++
 svgio/source/svgreader/svgtoken.cxx              |    2 
 7 files changed, 152 insertions(+), 2 deletions(-)

New commits:
commit b4219ea230a9635ca2422421324af5c407216e03
Author: Armin Le Grand <alg at apache.org>
Date:   Tue Jun 18 09:44:12 2013 +0000

    Resolves: #i122524# fixed some text import aspects for super/sub-baseline
    
    (cherry picked from commit def95cfb69619071811fb8e564eb4187f59f4b99)
    
    Conflicts:
    	svgio/source/svgreader/svgtoken.cxx
    
    Change-Id: I1208229a86807ce271a823415e9b8f0baf955e01

diff --git a/svgio/inc/svgio/svgreader/svgstyleattributes.hxx b/svgio/inc/svgio/svgreader/svgstyleattributes.hxx
index a84fd46..13e3705 100644
--- a/svgio/inc/svgio/svgreader/svgstyleattributes.hxx
+++ b/svgio/inc/svgio/svgreader/svgstyleattributes.hxx
@@ -143,6 +143,15 @@ namespace svgio
             FillRule_evenodd
         };
 
+        enum BaselineShift
+        {
+            BaselineShift_Baseline,
+            BaselineShift_Sub,
+            BaselineShift_Super,
+            BaselineShift_Percentage,
+            BaselineShift_Length
+        };
+
         class SvgStyleAttributes
         {
         private:
@@ -196,6 +205,10 @@ namespace svgio
             // ClipRule setting (only valid wne mbIsClipPathContent == true, default is FillRule_nonzero)
             FillRule                    maClipRule;
 
+            // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
+            BaselineShift               maBaselineShift;
+            SvgNumber                   maBaselineShiftNumber;
+
             /// bitfield
 
             // defines if this attributes are part of a ClipPath. If yes,
@@ -422,6 +435,11 @@ namespace svgio
             const SvgMarkerNode* accessMarkerEndXLink() const;
             void setMarkerEndXLink(const OUString& rNew) { maMarkerEndXLink = rNew; }
 
+            // BaselineShift
+            void setBaselineShift(const BaselineShift aBaselineShift = BaselineShift_Baseline) { maBaselineShift = aBaselineShift; }
+            BaselineShift getBaselineShift() const { return maBaselineShift; }
+            void setBaselineShiftNumber(const SvgNumber& rBaselineShift = SvgNumber()) { maBaselineShiftNumber = rBaselineShift; }
+            SvgNumber getBaselineShiftNumber() const;
         };
     } // end of namespace svgreader
 } // end of namespace svgio
diff --git a/svgio/inc/svgio/svgreader/svgtoken.hxx b/svgio/inc/svgio/svgreader/svgtoken.hxx
index 2e1f8c4..8594ca7 100644
--- a/svgio/inc/svgio/svgreader/svgtoken.hxx
+++ b/svgio/inc/svgio/svgreader/svgtoken.hxx
@@ -178,6 +178,7 @@ namespace svgio
 
             // text tokens
             SVGTokenText,
+            SVGTokenBaselineShift,
 
             SVGTokenLast
         };
diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx
index b154645..0d2d575 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -403,6 +403,38 @@ namespace svgio
                     }
                 }
 
+                // get BaselineShift
+                const BaselineShift aBaselineShift(rSvgStyleAttributes.getBaselineShift());
+
+                // apply BaselineShift
+                switch(aBaselineShift)
+                {
+                    case BaselineShift_Sub:
+                    {
+                        aPosition.setY(aPosition.getY() + aTextLayouterDevice.getUnderlineOffset());
+                        break;
+                    }
+                    case BaselineShift_Super:
+                    {
+                        aPosition.setY(aPosition.getY() + aTextLayouterDevice.getOverlineOffset());
+                        break;
+                    }
+                    case BaselineShift_Percentage:
+                    case BaselineShift_Length:
+                    {
+                        const SvgNumber aNumber(rSvgStyleAttributes.getBaselineShiftNumber());
+                        const double mfBaselineShift(aNumber.solve(*this, length));
+
+                        aPosition.setY(aPosition.getY() + mfBaselineShift);
+                        break;
+                    }
+                    default: // BaselineShift_Baseline
+                    {
+                        // nothing to do
+                        break;
+                    }
+                }
+
                 // get fill color
                 const basegfx::BColor aFill(rSvgStyleAttributes.getFill()
                     ? *rSvgStyleAttributes.getFill()
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index 3312221..3345f0b 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -80,9 +80,29 @@ namespace
                             {
                                 if(pLast)
                                 {
+                                    bool bAddGap(true);
+                                    static bool bNoGapsForBaselineShift(true);
+
+                                    if(bNoGapsForBaselineShift)
+                                    {
+                                        // With this option a baseline shift between two char parts ('words')
+                                        // will not add a space 'gap' to the end of the (non-last) word. This
+                                        // seems to be the standard behaviour, see last bugdoc attached #122524#
+                                        const svgio::svgreader::SvgStyleAttributes* pStyleLast = pLast->getSvgStyleAttributes();
+                                        const svgio::svgreader::SvgStyleAttributes* pStyleCurrent = pCandidate->getSvgStyleAttributes();
+
+                                        if(pStyleLast && pStyleCurrent && pStyleLast->getBaselineShift() != pStyleCurrent->getBaselineShift())
+                                        {
+                                            bAddGap = false;
+                                        }
+                                    }
+
                                     // add in-between whitespace (single space) to last
                                     // known character node
-                                    pLast->addGap();
+                                    if(bAddGap)
+                                    {
+                                        pLast->addGap();
+                                    }
                                 }
 
                                 // remember new last corected character node
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index bbd21d2..7cb7487 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -204,7 +204,7 @@ namespace svgio
                 }
                 else
                 {
-                    parseAttribute(aTokenName, StrToSVGToken(aTokenName), xAttribs->getValueByIndex(a));
+                    parseAttribute(aTokenName, aSVGToken, xAttribs->getValueByIndex(a));
                 }
             }
 
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 8d9c406..b7a128b 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1160,6 +1160,8 @@ namespace svgio
             mpMarkerEndXLink(0),
             maFillRule(FillRule_notset),
             maClipRule(FillRule_nonzero),
+            maBaselineShift(BaselineShift_Baseline),
+            maBaselineShiftNumber(0),
             mbIsClipPathContent(SVGTokenClipPathNode == mrOwner.getType()),
             mbStrokeDasharraySet(false)
         {
@@ -1794,6 +1796,43 @@ namespace svgio
                     }
                     break;
                 }
+                case SVGTokenBaselineShift:
+                {
+                    if(aContent.getLength())
+                    {
+                        static rtl::OUString aStrSub(rtl::OUString::createFromAscii("sub"));
+                        static rtl::OUString aStrSuper(rtl::OUString::createFromAscii("super"));
+                        SvgNumber aNum;
+
+                        if(aContent.match(aStrSub))
+                        {
+                            setBaselineShift(BaselineShift_Sub);
+                        }
+                        else if(aContent.match(aStrSuper))
+                        {
+                            setBaselineShift(BaselineShift_Super);
+                        }
+                        else if(readSingleNumber(aContent, aNum))
+                        {
+                            setBaselineShiftNumber(aNum);
+
+                            if(Unit_percent == aNum.getUnit())
+                            {
+                                setBaselineShift(BaselineShift_Percentage);
+                            }
+                            else
+                            {
+                                setBaselineShift(BaselineShift_Length);
+                            }
+                        }
+                        else
+                        {
+                            // no BaselineShift or inherit (which is automatically)
+                            setBaselineShift(BaselineShift_Baseline);
+                        }
+                    }
+                    break;
+                }
                 default:
                 {
                     break;
@@ -2175,6 +2214,24 @@ namespace svgio
         {
             if(maFontSize.isSet())
             {
+                // #122524# Handle Unit_percent realtive to parent FontSize (see SVG1.1
+                // spec 10.10 Font selection properties ‘font-size’, lastline (klick 'normative
+                // definition of the property')
+                if(Unit_percent == maFontSize.getUnit())
+                {
+                    const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
+
+                    if(pSvgStyleAttributes)
+                    {
+                        const SvgNumber aParentNumber = pSvgStyleAttributes->getFontSize();
+
+                        return SvgNumber(
+                            aParentNumber.getNumber() * maFontSize.getNumber() * 0.01,
+                            aParentNumber.getUnit(),
+                            true);
+                    }
+                }
+
                 return maFontSize;
             }
 
@@ -2463,6 +2520,26 @@ namespace svgio
             return mpMarkerEndXLink;
         }
 
+        SvgNumber SvgStyleAttributes::getBaselineShiftNumber() const
+        {
+            // #122524# Handle Unit_percent realtive to parent BaselineShift
+            if(Unit_percent == maBaselineShiftNumber.getUnit())
+            {
+                const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
+
+                if(pSvgStyleAttributes)
+                {
+                    const SvgNumber aParentNumber = pSvgStyleAttributes->getBaselineShiftNumber();
+
+                    return SvgNumber(
+                        aParentNumber.getNumber() * maBaselineShiftNumber.getNumber() * 0.01,
+                        aParentNumber.getUnit(),
+                        true);
+                }
+            }
+
+            return maBaselineShiftNumber;
+        }
     } // end of namespace svgreader
 } // end of namespace svgio
 
diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx
index e402085..ab64e7d 100644
--- a/svgio/source/svgreader/svgtoken.cxx
+++ b/svgio/source/svgreader/svgtoken.cxx
@@ -160,6 +160,7 @@ namespace svgio
         static OUString aSVGStrStrokeWidth(OUString::createFromAscii("stroke-width"));
 
         static OUString aSVGStrText(OUString::createFromAscii("text"));
+        static OUString aSVGStrBaselineShift(OUString::createFromAscii("baseline-shift"));
 
         SVGToken StrToSVGToken(const OUString& rStr)
         {
@@ -302,6 +303,7 @@ namespace svgio
                 aSVGTokenMapperList.insert(SVGTokenValueType(aSVGStrStrokeWidth, SVGTokenStrokeWidth));
 
                 aSVGTokenMapperList.insert(SVGTokenValueType(aSVGStrText, SVGTokenText));
+                aSVGTokenMapperList.insert(SVGTokenValueType(aSVGStrBaselineShift, SVGTokenBaselineShift));
             }
 
             const SVGTokenMapper::const_iterator aResult(aSVGTokenMapperList.find(rStr.startsWith("svg:") ? rStr.copy(4) : rStr));


More information about the Libreoffice-commits mailing list