summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorArmin Le Grand <alg@apache.org>2013-06-18 09:44:12 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-06-18 13:21:20 +0100
commitb4219ea230a9635ca2422421324af5c407216e03 (patch)
tree97e4b1e70d224ee92f41821d05c7f82ebf8287f1 /svgio
parent3b3a0ae27906e534ad7b80b6eeb76cdda71a33ac (diff)
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
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgio/svgreader/svgstyleattributes.hxx18
-rw-r--r--svgio/inc/svgio/svgreader/svgtoken.hxx1
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx32
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx22
-rw-r--r--svgio/source/svgreader/svgnode.cxx2
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx77
-rw-r--r--svgio/source/svgreader/svgtoken.cxx2
7 files changed, 152 insertions, 2 deletions
diff --git a/svgio/inc/svgio/svgreader/svgstyleattributes.hxx b/svgio/inc/svgio/svgreader/svgstyleattributes.hxx
index a84fd4648e98..13e37057af41 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 2e1f8c43b036..8594ca720a71 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 b154645bb2bd..0d2d575718f2 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 3312221bfcaf..3345f0b9d68f 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 bbd21d21487e..7cb74875d287 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 8d9c406ab744..b7a128bf9a48 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 e40208527171..ab64e7d8425f 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));