Browse Source

Fixes the coordinates, dpi value and text rendering of the svg output of fpvectorial

git-svn-id: trunk@15928 -
sekelsenmat 15 years ago
parent
commit
9a66b19390

+ 2 - 1
packages/fpvectorial/src/fpvectbuildunit.pas

@@ -3,7 +3,8 @@ unit fpvectbuildunit;
 interface
 Uses
    avisocncgcodereader,avisocncgcodewriter,avisozlib,fpvectorial,
-   fpvtocanvas,pdfvectorialreader,pdfvrlexico,pdfvrsemantico,pdfvrsintatico;
+   fpvtocanvas,pdfvectorialreader,pdfvrlexico,pdfvrsemantico,pdfvrsintatico,
+   svgvectorialwriter,cdrvectorialreader;
 
 implementation
 end.

+ 8 - 10
packages/fpvectorial/src/fpvectorial.pas

@@ -438,21 +438,19 @@ var
   lText: PText;
 begin
   lText := GetMem(SizeOf(TvText));
-  SetLength(lText.Value, Length(AText));
-  Move(AText[1], lText.Value[1], Length(AText));
-  lText.X:=AX;
-  lText.Y:=AY;
-  lText.Z:=AZ;
-  //lText.FontName:=FontName;
-  SetLength(lText.FontName, Length(FontName));
-  Move(FontName[1], lText.FontName[1], Length(FontName));
-  lText.FontSize:=FontSize;
+  FillChar(lText^, SizeOf(TvText), 0);
+  lText.Value := AText;
+  lText.X := AX;
+  lText.Y := AY;
+  lText.Z := AZ;
+  lText.FontName := FontName;
+  lText.FontSize := FontSize;
   FTexts.Add(lText);
 end;
 
 procedure TvVectorialDocument.AddText(AX, AY, AZ: Double; AStr: utf8string);
 begin
-  AddText(AX, AY, AZ, 'Arial', 10, AStr);
+  AddText(AX, AY, AZ, '', 10, AStr);
 end;
 
 {@@

+ 66 - 68
packages/fpvectorial/src/svgvectorialwriter.pas

@@ -37,7 +37,14 @@ type
 implementation
 
 const
-  FLOAT_MILIMETERS_PER_PIXEL = 0.3528;
+  // SVG requires hardcoding a DPI value
+
+  // The Opera Browser and Inkscape use 90 DPI, so we follow that
+
+  // 1 Inch = 25.4 milimiters
+  // 90 inches per pixel = (1 / 90) * 25.4 = 0.2822
+  // FLOAT_MILIMETERS_PER_PIXEL = 0.3528; // DPI 72 = 1 / 72 inches per pixel
+  FLOAT_MILIMETERS_PER_PIXEL = 0.2822; // DPI 90 = 1 / 90 inches per pixel
 
 { TvSVGVectorialWriter }
 
@@ -85,10 +92,7 @@ begin
       if (lPath.Points[j].SegmentType <> st2DLine)
         and (lPath.Points[j].SegmentType <> stMoveTo)
         then Break; // unsupported line type
-//      PtX := lPath.Points[j].X;
-//      PtY := lPath.Points[j].Y;
-//      PathStr := PathStr + FloatToStr(PtX, FPointSeparator) + ','  // + 'mm,'
-//        + FloatToStr(PtY, FPointSeparator) + ' '; // + 'mm ';
+
       // Coordinate conversion from fpvectorial to SVG
       ConvertFPVCoordinatesToSVGCoordinates(
         AData, lPath.Points[j].X, lPath.Points[j].Y, PtX, PtY);
@@ -159,29 +163,28 @@ end;
 procedure TvSVGVectorialWriter.WriteTexts(AStrings: TStrings; AData: TvVectorialDocument);
 var
   i, j, FontSize: Integer;
-  TextStr, FontName: string;
-  ltest: TvText;
+  TextStr, FontName, SVGFontFamily: string;
+  lText: TvText;
   PtX, PtY: double;
 begin
   for i := 0 to AData.GetTextCount() - 1 do
   begin
     TextStr := '';
-    ltest := AData.GetText(i);
-    //PtX := ltest.X;
-    //PtY := ltest.Y;
+    lText := AData.GetText(i);
+
     ConvertFPVCoordinatesToSVGCoordinates(
-        AData, ltest.X, ltest.Y, PtX, PtY);
-    TextStr := ltest.Value;
-    FontSize:= ceil(ltest.FontSize / FLOAT_MILIMETERS_PER_PIXEL);
-    FontName:=ltest.FontName;
-    AStrings.Add('  <text');
-    AStrings.Add('    style="font-size:'
-    +IntToStr(FontSize)+'px;font-style:normal;font-weight:normal;line-height:125%;'
-    +'letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;'
-    +'font-family:'+FontName+'"><tspan');
-    AStrings.Add('     x="' + FloatToStr(PtX, FPointSeparator) + '"');
-    AStrings.Add('     y="' + FloatToStr(PtY, FPointSeparator) + '"');
-    AStrings.Add('     id="tspan3071">' + TextStr + '</tspan></text>');
+        AData, lText.X, lText.Y, PtX, PtY);
+
+    TextStr := lText.Value;
+    FontSize:= ceil(lText.FontSize / FLOAT_MILIMETERS_PER_PIXEL);
+    SVGFontFamily := 'Arial, sans-serif';//lText.FontName;
+
+    AStrings.Add('  <text ');
+    AStrings.Add('    x="' + FloatToStr(PtX, FPointSeparator) + '"');
+    AStrings.Add('    y="' + FloatToStr(PtY, FPointSeparator) + '"');
+    AStrings.Add('    font-size="' + IntToStr(FontSize) + '"');
+    AStrings.Add('    font-family="' + SVGFontFamily + '">');
+    AStrings.Add(TextStr + '</text>');
   end;
 end;
 
@@ -209,58 +212,53 @@ begin
     begin
       BezierType := lPath.Points[j].SegmentType;
       if j>0 then
-      if (BezierType <> st2DBezier) and (BezierType <> st3DBezier)
-        and (BezierType<> st2DLine)
+      if (BezierType <> st2DBezier) and (BezierType <> stMoveTo)
+        and (BezierType <> st2DLine)
       then Break; // unsupported Bezier type
 
-      //ConvertFPVCoordinatesToSVGCoordinates(
-      //  AData, lPath.Points[j].X, lPath.Points[j].Y, PtX, PtY);
-
       if (BezierType = st2DBezier) or (BezierType = stMoveTo) then
       begin
-      PtX  := lPath.Points[j].X / FLOAT_MILIMETERS_PER_PIXEL;
-      PtY  := (AData.Height - lPath.Points[j].Y) / FLOAT_MILIMETERS_PER_PIXEL;
-      PtX2 := lPath.Points[j].X2 / FLOAT_MILIMETERS_PER_PIXEL;
-      PtY2 := (AData.Height - lPath.Points[j].Y2) / FLOAT_MILIMETERS_PER_PIXEL;
-      PtX3 := lPath.Points[j].X3 / FLOAT_MILIMETERS_PER_PIXEL;
-      PtY3 := (AData.Height - lPath.Points[j].Y3) / FLOAT_MILIMETERS_PER_PIXEL;
-
-      PtX  := PtX - OldPtX;
-      PtY  := PtY - OldPtY;
-      PtX2 := PtX2 - OldPtX2;
-      PtY2 := PtY2 - OldPtY2;
-      PtX3 := PtX3 - OldPtX3;
-      PtY3 := PtY3 - OldPtY3;
-
-      if j = 0 then
-        PathStr := PathStr + FloatToStr(PtX, FPointSeparator) + ','
-          + FloatToStr(PtY, FPointSeparator) + ' ';
-
-      if j = 0 then
-      begin
- //       if BezierType = st2DBezier then
+        ConvertFPVCoordinatesToSVGCoordinates(
+         AData, lPath.Points[j].X, lPath.Points[j].Y, PtX, PtY);
+        ConvertFPVCoordinatesToSVGCoordinates(
+         AData, lPath.Points[j].X2, lPath.Points[j].Y2, PtX2, PtY2);
+        ConvertFPVCoordinatesToSVGCoordinates(
+         AData, lPath.Points[j].X3, lPath.Points[j].Y3, PtX3, PtY3);
+
+        PtX  := PtX - OldPtX;
+        PtY  := PtY - OldPtY;
+        PtX2 := PtX2 - OldPtX2;
+        PtY2 := PtY2 - OldPtY2;
+        PtX3 := PtX3 - OldPtX3;
+        PtY3 := PtY3 - OldPtY3;
+
+        if j = 0 then
+          PathStr := PathStr + FloatToStr(PtX, FPointSeparator) + ','
+            + FloatToStr(PtY, FPointSeparator) + ' ';
+
+        if j = 0 then
+        begin
           PathStr := PathStr + 'q';
-        if BezierType = st3DBezier then
-          PathStr := PathStr + 'c';
+//          if BezierType = st3DBezier then
+//            PathStr := PathStr + 'c';
+        end;
+
+        if j > 0 then
+          PathStr := PathStr + FloatToStr(PtX, FPointSeparator) + ','
+            + FloatToStr(PtY, FPointSeparator) + ' '
+            + FloatToStr(PtX2, FPointSeparator) + ','
+            + FloatToStr(PtY2, FPointSeparator) + ' '
+            + FloatToStr(PtX3, FPointSeparator) + ','
+            + FloatToStr(PtY3, FPointSeparator) + ' ';
+
+        // Store the current position for future points
+        OldPtX  := OldPtX + PtX;
+        OldPtY  := OldPtY + PtY;
+        OldPtX2 := OldPtX2 + PtX2;
+        OldPtY2 := OldPtY2 + PtY2;
+        OldPtX3 := OldPtX3 + PtX3;
+        OldPtY3 := OldPtY3 + PtY3;
       end;
-
-      if j > 0 then
-        PathStr := PathStr + FloatToStr(PtX, FPointSeparator) + ','
-          + FloatToStr(PtY, FPointSeparator) + ' '
-          + FloatToStr(PtX2, FPointSeparator) + ','
-          + FloatToStr(PtY2, FPointSeparator) + ' '
-          + FloatToStr(PtX3, FPointSeparator) + ','
-          + FloatToStr(PtY3, FPointSeparator) + ' ';
-
-      // Store the current position for future points
-      OldPtX  := OldPtX + PtX;
-      OldPtY  := OldPtY + PtY;
-      OldPtX2 := OldPtX2 + PtX2;
-      OldPtY2 := OldPtY2 + PtY2;
-      OldPtX3 := OldPtX3 + PtX3;
-      OldPtY3 := OldPtY3 + PtY3;
-    end;
-
     end;
 
     AStrings.Add('  <path');