Browse Source

fpvectorial: Adds multiline support for text, adds a new translate function to entities

git-svn-id: trunk@18260 -
sekelsenmat 14 years ago
parent
commit
658be2b0b7

+ 23 - 2
packages/fpvectorial/src/fpvectorial.pas

@@ -163,6 +163,7 @@ type
     procedure CalculateBoundingBox(var ALeft, ATop, ARight, ABottom: Double); virtual;
     procedure ExpandBoundingBox(var ALeft, ATop, ARight, ABottom: Double);
     function TryToSelect(APos: TPoint): TvFindEntityResult; virtual;
+    procedure Translate(ADeltaX, ADeltaY: Integer); virtual;
   end;
 
   TvClipMode = (vcmNonzeroWindingRule, vcmEvenOddRule);
@@ -189,8 +190,10 @@ type
 
   TvText = class(TvEntity)
   public
-    Value: utf8string;
+    Value: TStringList;
     Font: TvFont;
+    constructor Create; override;
+    destructor Destroy; override;
     function TryToSelect(APos: TPoint): TvFindEntityResult; override;
   end;
 
@@ -489,6 +492,18 @@ end;
 
 { TvText }
 
+constructor TvText.Create;
+begin
+  inherited Create;
+  Value := TStringList.Create;
+end;
+
+destructor TvText.Destroy;
+begin
+  Value.Free;
+  inherited Destroy;
+end;
+
 function TvText.TryToSelect(APos: TPoint): TvFindEntityResult;
 var
   lProximityFactor: Integer;
@@ -534,6 +549,12 @@ begin
   Result := vfrNotFound;
 end;
 
+procedure TvEntity.Translate(ADeltaX, ADeltaY: Integer);
+begin
+  X := X + ADeltaX;
+  Y := Y + ADeltaY;
+end;
+
 { TvEllipse }
 
 procedure TvEllipse.CalculateBoundingRectangle;
@@ -825,7 +846,7 @@ var
   lText: TvText;
 begin
   lText := TvText.Create;
-  lText.Value := AText;
+  lText.Value.Text := AText;
   lText.X := AX;
   lText.Y := AY;
   lText.Font.Name := FontName;

+ 8 - 2
packages/fpvectorial/src/fpvtocanvas.pas

@@ -548,8 +548,14 @@ begin
   ALCLDest.Font.Orientation := Round(CurText.Font.Orientation * 16);
   {$endif}
 
-  LowerDim.Y := CurText.Y + CurText.Font.Size;
-  ADest.TextOut(CoordToCanvasX(CurText.X), CoordToCanvasY(LowerDim.Y), CurText.Value);
+  // TvText supports multiple lines
+  for i := 0 to CurText.Value.Count - 1 do
+  begin
+    if CurText.Font.Size = 0 then LowerDim.Y := CurText.Y - 12 * (i + 1)
+    else LowerDim.Y := CurText.Y - CurText.Font.Size * (i + 1);
+
+    ADest.TextOut(CoordToCanvasX(CurText.X), CoordToCanvasY(LowerDim.Y), CurText.Value.Strings[i]);
+  end;
 end;
 
 end.

+ 1 - 1
packages/fpvectorial/src/svgvectorialwriter.pas

@@ -232,7 +232,7 @@ begin
   ConvertFPVCoordinatesToSVGCoordinates(
       AData, lText.X, lText.Y, PtX, PtY);
 
-  TextStr := lText.Value;
+  TextStr := lText.Value.Text;
   FontSize:= ceil(lText.Font.Size / FLOAT_MILIMETERS_PER_PIXEL);
   SVGFontFamily := 'Arial, sans-serif';//lText.FontName;