From 97bb2976263e27a45948fbecd3bb2ce698e8830a Mon Sep 17 00:00:00 2001 From: Carlos Amengual Date: Tue, 29 Jun 2021 19:11:01 +0200 Subject: [PATCH] svg1.2: support attribute text-align="center" in SVG 1.2 flow elements. Closes #33 --- .../carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java | 3 ++- .../echosvg/css/engine/value/svg12/SVG12ValueConstants.java | 5 +++-- .../echosvg/css/engine/value/svg12/TextAlignManager.java | 5 ++++- .../java/io/sf/carte/echosvg/util/SVG12CSSConstants.java | 4 +--- samples/tests/spec12/text/flowText.svg | 2 +- samples/tests/spec12/text/flowText2.svg | 2 +- samples/tests/spec12/text/flowText3.svg | 2 +- samples/tests/spec12/text/flowText4.svg | 2 +- samples/tests/spec12/text/flowText5.svg | 4 ++-- 9 files changed, 16 insertions(+), 13 deletions(-) diff --git a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java index b8b7df782..d9f3155b3 100644 --- a/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java +++ b/echosvg-bridge/src/main/java/io/sf/carte/echosvg/bridge/svg12/SVGFlowRootElementBridge.java @@ -61,6 +61,7 @@ import io.sf.carte.echosvg.css.engine.value.ComputedValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueConstants; +import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; import io.sf.carte.echosvg.css.engine.value.svg12.LineHeightValue; import io.sf.carte.echosvg.css.engine.value.svg12.SVG12ValueConstants; import io.sf.carte.echosvg.dom.AbstractNode; @@ -855,7 +856,7 @@ public BlockInfo makeBlockInfo(BridgeContext ctx, Element element) { int textAlign; if (v == SVG12ValueConstants.START_VALUE) textAlign = BlockInfo.ALIGN_START; - else if (v == SVG12ValueConstants.MIDDLE_VALUE) + else if (v == SVG12ValueConstants.CENTER_VALUE || v == SVGValueConstants.MIDDLE_VALUE) textAlign = BlockInfo.ALIGN_MIDDLE; else if (v == SVG12ValueConstants.END_VALUE) textAlign = BlockInfo.ALIGN_END; diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java index 00340e421..0d53a5355 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/SVG12ValueConstants.java @@ -24,6 +24,7 @@ import io.sf.carte.echosvg.css.engine.value.StringValue; import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; +import io.sf.carte.echosvg.util.CSSConstants; import io.sf.carte.echosvg.util.SVG12CSSConstants; /** @@ -37,8 +38,8 @@ public interface SVG12ValueConstants extends SVGValueConstants { /** The 'start' keyword. */ Value START_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_FULL_VALUE); - /** The 'middle' keyword. */ - Value MIDDLE_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_MIDDLE_VALUE); + /** The 'center' keyword. */ + Value CENTER_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, CSSConstants.CSS_CENTER_VALUE); /** The 'end' keyword. */ Value END_VALUE = new StringValue(CSSPrimitiveValue.CSS_IDENT, SVG12CSSConstants.CSS_END_VALUE); /** The 'full' keyword. */ diff --git a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/TextAlignManager.java b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/TextAlignManager.java index 3966391dd..26aee7c15 100644 --- a/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/TextAlignManager.java +++ b/echosvg-css/src/main/java/io/sf/carte/echosvg/css/engine/value/svg12/TextAlignManager.java @@ -24,6 +24,8 @@ import io.sf.carte.echosvg.css.engine.value.Value; import io.sf.carte.echosvg.css.engine.value.ValueConstants; import io.sf.carte.echosvg.css.engine.value.ValueManager; +import io.sf.carte.echosvg.css.engine.value.svg.SVGValueConstants; +import io.sf.carte.echosvg.util.CSSConstants; import io.sf.carte.echosvg.util.SVG12CSSConstants; import io.sf.carte.echosvg.util.SVGTypes; @@ -43,7 +45,8 @@ public class TextAlignManager extends IdentifierManager { static { values.put(SVG12CSSConstants.CSS_START_VALUE, SVG12ValueConstants.START_VALUE); - values.put(SVG12CSSConstants.CSS_MIDDLE_VALUE, SVG12ValueConstants.MIDDLE_VALUE); + values.put(CSSConstants.CSS_CENTER_VALUE, SVG12ValueConstants.CENTER_VALUE); + values.put(CSSConstants.CSS_MIDDLE_VALUE, SVGValueConstants.MIDDLE_VALUE); values.put(SVG12CSSConstants.CSS_END_VALUE, SVG12ValueConstants.END_VALUE); values.put(SVG12CSSConstants.CSS_FULL_VALUE, SVG12ValueConstants.FULL_VALUE); } diff --git a/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java b/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java index 68ba46f2a..796423078 100644 --- a/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java +++ b/echosvg-util/src/main/java/io/sf/carte/echosvg/util/SVG12CSSConstants.java @@ -41,7 +41,7 @@ public interface SVG12CSSConstants extends CSSConstants { String CSS_MARGIN_LEFT_PROPERTY = "margin-left"; /** property name for indent */ String CSS_INDENT_PROPERTY = "indent"; - /** propery name for text-align */ + /** property name for text-align */ String CSS_TEXT_ALIGN_PROPERTY = "text-align"; /** property name for color attribute */ String CSS_SOLID_COLOR_PROPERTY = "solid-color"; @@ -50,8 +50,6 @@ public interface SVG12CSSConstants extends CSSConstants { /** Value for text-align to start of text on line */ String CSS_START_VALUE = "start"; - /** Value for text-align to middle of text on line */ - String CSS_MIDDLE_VALUE = "middle"; /** Value for text-align to end of region */ String CSS_END_VALUE = "end"; /** Value for text-align to both edges of region */ diff --git a/samples/tests/spec12/text/flowText.svg b/samples/tests/spec12/text/flowText.svg index 629edc8ee..efd74cdc1 100644 --- a/samples/tests/spec12/text/flowText.svg +++ b/samples/tests/spec12/text/flowText.svg @@ -66,7 +66,7 @@ This is an ex­ample of a very long string that is split ‍across multi­ple lines via text wrap­ping. Now check if text wrapping handles some tricky stuff: a­very­long­runon­word­that­spans­multiple­lines­with­embed­span­elements & super or sub scripts. We are just about to go to the next flow rect (NOTE: if the 'about' were included on the last line of the previous flow the line would not have fit in the region, so it is moved to this flowRegion). - I want to make sure that it stops when it hits the end of all of the flowRegions defined. Also the last line includes text in a larger font size so it will not fit. The end of this sentence will be cut off because the line size gets taller + I want to make sure that it stops when it hits the end of all of the flowRegions defined. Also the last line includes text in a larger font size so it will not fit. The end of this sentence will be cut off because the line size gets taller diff --git a/samples/tests/spec12/text/flowText2.svg b/samples/tests/spec12/text/flowText2.svg index 6b0967c08..a36d03c0c 100644 --- a/samples/tests/spec12/text/flowText2.svg +++ b/samples/tests/spec12/text/flowText2.svg @@ -66,7 +66,7 @@ This is an ex­ample of a very long string that is split ‍across multi­ple lines via text wrap­ping. Now check if text wrapping handles a number of tricky situations: a­very­long­runon­word­that­spans­multiple­lines­with­embedded­span­elements & super or sub scripts. Now we are just about to go to the next flow rect (note if the 'about' were included on the last line of the previous flow rect the line would not have fit and the whole line would have moved here). - I'll keep going because I want to make sure that it properly stops when it hits the end of all of the the flow regions defined. Also the last line includes text in a larger font size so it will not fit. Thus the end of this sentence will be cut off because the line size gets taller + I'll keep going because I want to make sure that it properly stops when it hits the end of all of the the flow regions defined. Also the last line includes text in a larger font size so it will not fit. Thus the end of this sentence will be cut off because the line size gets taller diff --git a/samples/tests/spec12/text/flowText3.svg b/samples/tests/spec12/text/flowText3.svg index 4b190d338..c1c5a12fb 100644 --- a/samples/tests/spec12/text/flowText3.svg +++ b/samples/tests/spec12/text/flowText3.svg @@ -59,7 +59,7 @@ This is an ex­ample of a very long string that is split ‍across multi­ple lines via text wrap­ping. - Now check if text wrapping handles a number of tricky situations: a­very­long­runon­word­that­spans­multiple­lines­with­embedded­span­elements & super or sub scripts. + Now check if text wrapping handles a number of tricky situations: a­very­long­runon­word­that­spans­multiple­lines­with­embedded­span­elements & super or sub scripts. Now we are just about to go to the next flow rect (note if the 'about' were included on the last line of the previous flow rect the line would not have fit and the whole line would have moved here). I'll keep going because I want to make sure that it properly stops when it hits the end of all of the the flow regions defined. Also the last line includes text in a larger font size so it will not fit. Thus the end of this sentence will be cut off because the line size gets taller diff --git a/samples/tests/spec12/text/flowText4.svg b/samples/tests/spec12/text/flowText4.svg index 8d8d4579e..bc7efa416 100644 --- a/samples/tests/spec12/text/flowText4.svg +++ b/samples/tests/spec12/text/flowText4.svg @@ -54,7 +54,7 @@ This is an ex­ample of a very long string that is split ‍across multi­ple lines via text wrap­ping. - Now check if text wrapping handles a number of tricky situations: a­very­long­runon­word­that­spans­multiple­lines­with­embedded­span­elements & super or sub scripts. + Now check if text wrapping handles a number of tricky situations: a­very­long­runon­word­that­spans­multiple­lines­with­embedded­span­elements & super or sub scripts. Now we are just about to go to the next flow rect (note if the 'about' were included on the last line of the previous flow rect the line would not have fit and the whole line would have moved here). I'll keep going because I want to make sure that it properly stops when it hits the end of all of the the flow regions defined. Also the last line includes text in a larger font size so it will not fit. Thus the end of this sentence will be cut off because the line size gets taller and taller. diff --git a/samples/tests/spec12/text/flowText5.svg b/samples/tests/spec12/text/flowText5.svg index 41f6f9b53..26f93856e 100644 --- a/samples/tests/spec12/text/flowText5.svg +++ b/samples/tests/spec12/text/flowText5.svg @@ -50,7 +50,7 @@ - Tomorrow, and tomorrow, and tomorrow, + Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our yesterdays have lighted fools @@ -85,7 +85,7 @@ - Tomorrow, and tomorrow, and tomorrow, + Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our yesterdays have lighted fools