QCAD

QCAD - 2D CAD System.

Click here for a documentation of the DokuWiki formatting syntax that can be used in reports

Please search for existing tasks (also closed ones) before opening a new task.

Please make sure that you are using the latest Version of QCAD before posting a bug (menu Help - Check for Updates)

Tasklist

FS#421 - Multiline Text in SVG Exporter PG

Attached to Project: QCAD
Opened by Peter (hungerburg) - Wednesday, 07 December 2011, 13:04 GMT+2
Last edited by Andrew (andrew) - Wednesday, 07 December 2011, 16:14 GMT+2
Task Type Bug Report
Category Main
Status Closed
Assigned To Andrew (andrew)
Operating System All
Severity Low
Priority Normal
Reported Version 3 RC2
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Multiline text is in the wrong place. Please see patch below:

— SvgExporterPG.js~ 2011-11-04 22:08:57.000000000 +0100
+++ SvgExporterPG.js 2011-12-07 13:01:43.811533803 +0100
@@ -248,7 +248,8 @@

   this.writeStartElement("flowRoot"); // <flowRoot>
   this.writeFontAttributes();
   var bb = this.text.getBoundingBox();

- var pos = this.text.getPosition();
+ var pos = this.text.getPosition(); always (0,0) ?
+ var pos = bb.getCenter(); // still not right, but closer

   var x = this.convert(pos.x);
   var y = this.convert(pos.y);
   var a = 360 - RMath.rad2deg(this.text.getAngle());
This task depends upon

Closed by  Andrew (andrew)
Wednesday, 07 December 2011, 16:14 GMT+2
Reason for closing:  Fixed
Additional comments about closing:  r19941
Comment by Peter (hungerburg) - Wednesday, 07 December 2011, 13:06 GMT+2

Better readable patch:

--- SvgExporterPG.js~	2011-11-04 22:08:57.000000000 +0100
+++ SvgExporterPG.js	2011-12-07 13:01:43.811533803 +0100
@@ -248,7 +248,8 @@
     this.writeStartElement("flowRoot"); // <flowRoot>
     this.writeFontAttributes();
     var bb = this.text.getBoundingBox();
-    var pos = this.text.getPosition();
+    //var pos = this.text.getPosition(); // always (0,0) ?
+    var pos = bb.getCenter(); // still not right, but closer
     var x = this.convert(pos.x);
     var y = this.convert(pos.y);
Comment by Andrew (andrew) - Wednesday, 07 December 2011, 16:13 GMT+2

Thanks.

Here's a refactored and fixed method exportMultiLineText:

SvgExporterPG.prototype.exportMultiLineText = function() {
    // <flowRoot>
    //   <flowRegion>
    //     <rect width="54.667633" height="28.062719" x="38.44957"
    //       y="5.6952629"/>
    //   </flowRegion>
    //   <flowPara>line1</flowPara>
    //   <flowPara>line2</flowPara>
    // </flowRoot>
 
    this.writeStartElement("flowRoot");
    this.writeFontAttributes();
    var bb = this.text.getBoundingBox();
    var pos = this.text.getAlignmentPoint();
    var x = this.convert(pos.x);
    var y = this.convert(pos.y);
    var a = RMath.rad2deg(this.text.getAngle());
    var tw = this.text.getWidth();
    var th = this.text.getHeight();
 
    // adds some additional space to be sure all characters are shown:
    var additionalSpaceFactor = 1.5;
     
    var tx = 0;
    var alignmentStyle = "";
    switch (this.text.getHAlign()) {
    case RS.HAlignLeft:
    case RS.HAlignAlign:
    case RS.HAlignFit:
        break;
    case RS.HAlignCenter:
    case RS.HAlignMid:
        tx = - tw / 2 * additionalSpaceFactor;
        alignmentStyle = "text-anchor:middle;text-align:center";
        break;
    case RS.HAlignRight:
        tx = - tw * additionalSpaceFactor;
        alignmentStyle = "text-anchor:end;text-align:end"
        break;
    }
 
    var ty = 0;
    switch (this.text.getVAlign()) {
    case RS.VAlignTop:
        break;
    case RS.VAlignMiddle:
        ty = -th/2;
        break;
    case RS.VAlignBase:
    case RS.VAlignBottom:
        ty = -th;
        break;
    }
 
    this.writeAttribute("transform",
                        "scale(1,-1) " +
                        "rotate(" + (360 - a) + ", " + pos.x + ", " + -pos.y + ") " +
                        "translate(" + tx + ", " + ty + ")");
 
    this.writeStartElement("flowRegion");
    this.writeStartElement("rect");
 
    this.writeAttribute("width", tw * additionalSpaceFactor);
    this.writeAttribute("height", th * additionalSpaceFactor);
    this.writeAttribute("x", pos.x);
    this.writeAttribute("y", -pos.y);
    this.writeEndElement("rect");
    this.writeEndElement("flowRegion");
    var text = this.text.getPlainText();
    var lines = text.split(/\r\n|\r|\n/);
    for ( var i = 0; i < lines.length; ++i) {
        // <flowPara>line1</flowPara>
        this.writeStartElement("flowPara");
        if (alignmentStyle!=="") {
            this.writeAttribute("style", alignmentStyle);
        }
        this.exportLineText(lines[i]);
        this.writeEndElement("flowPara");
    }
    this.writeEndElement("flowRoot");
};

Loading...