mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 18:00:57 +02:00
fpvectorial: Many improvements to svg read coordinates and parts of svg read
git-svn-id: trunk@39668 -
This commit is contained in:
parent
bdb2463866
commit
e2d0c4d4f6
@ -109,18 +109,31 @@ end;
|
|||||||
procedure TSVGPathTokenizer.AddToken(AStr: string);
|
procedure TSVGPathTokenizer.AddToken(AStr: string);
|
||||||
var
|
var
|
||||||
lToken: TSVGToken;
|
lToken: TSVGToken;
|
||||||
|
lStr: string;
|
||||||
begin
|
begin
|
||||||
lToken := TSVGToken.Create;
|
lToken := TSVGToken.Create;
|
||||||
|
|
||||||
if AStr = 'm' then lToken.TokenType := sttMoveTo
|
lStr := LowerCase(AStr);
|
||||||
else if AStr = 'l' then lToken.TokenType := sttLineTo
|
if lStr = '' then Exit;
|
||||||
else if AStr = 'c' then lToken.TokenType := sttBezierTo
|
|
||||||
|
if lStr[1] = 'm' then lToken.TokenType := sttMoveTo
|
||||||
|
else if lStr[1] = 'l' then lToken.TokenType := sttLineTo
|
||||||
|
else if lStr[1] = 'c' then lToken.TokenType := sttBezierTo
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
lToken.TokenType := sttFloatValue;
|
lToken.TokenType := sttFloatValue;
|
||||||
lToken.Value := StrToFloat(AStr, FPointSeparator);
|
lToken.Value := StrToFloat(AStr, FPointSeparator);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Sometimes we get a command glued to a value, for example M150
|
||||||
|
if (lToken.TokenType <> sttFloatValue) and (Length(lStr) > 1) then
|
||||||
|
begin
|
||||||
|
Tokens.Add(lToken);
|
||||||
|
lToken.TokenType := sttFloatValue;
|
||||||
|
lStr := Copy(AStr, 2, Length(AStr));
|
||||||
|
lToken.Value := StrToFloat(lStr, FPointSeparator);
|
||||||
|
end;
|
||||||
|
|
||||||
Tokens.Add(lToken);
|
Tokens.Add(lToken);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -526,9 +539,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ConvertSVGCoordinatesToFPVCoordinates(
|
ConvertSVGDeltaToFPVDelta(
|
||||||
AData, cx, cy, lCircle.X, lCircle.Y);
|
AData, cx, cy, lCircle.X, lCircle.Y);
|
||||||
ConvertSVGCoordinatesToFPVCoordinates(
|
ConvertSVGDeltaToFPVDelta(
|
||||||
AData, cr, 0, lCircle.Radius, dtmp);
|
AData, cr, 0, lCircle.Radius, dtmp);
|
||||||
|
|
||||||
AData.AddEntity(lCircle);
|
AData.AddEntity(lCircle);
|
||||||
@ -574,9 +587,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ConvertSVGCoordinatesToFPVCoordinates(
|
ConvertSVGDeltaToFPVDelta(
|
||||||
AData, cx, cy, lEllipse.X, lEllipse.Y);
|
AData, cx, cy, lEllipse.X, lEllipse.Y);
|
||||||
ConvertSVGCoordinatesToFPVCoordinates(
|
ConvertSVGDeltaToFPVDelta(
|
||||||
AData, crx, cry, lEllipse.HorzHalfAxis, lEllipse.VertHalfAxis);
|
AData, crx, cry, lEllipse.HorzHalfAxis, lEllipse.VertHalfAxis);
|
||||||
|
|
||||||
AData.AddEntity(lEllipse);
|
AData.AddEntity(lEllipse);
|
||||||
@ -586,6 +599,7 @@ procedure TvSVGVectorialReader.ReadLineFromNode(ANode: TDOMNode;
|
|||||||
AData: TvVectorialPage; ADoc: TvVectorialDocument);
|
AData: TvVectorialPage; ADoc: TvVectorialDocument);
|
||||||
var
|
var
|
||||||
x1, y1, x2, y2: double;
|
x1, y1, x2, y2: double;
|
||||||
|
vx1, vy1, vx2, vy2: double;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
lNodeName: DOMString;
|
lNodeName: DOMString;
|
||||||
begin
|
begin
|
||||||
@ -615,9 +629,14 @@ begin
|
|||||||
end;}
|
end;}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
ConvertSVGCoordinatesToFPVCoordinates(
|
||||||
|
AData, x1, y1, vx1, vy1);
|
||||||
|
ConvertSVGCoordinatesToFPVCoordinates(
|
||||||
|
AData, x2, y2, vx2, vy2);
|
||||||
|
|
||||||
AData.StartPath();
|
AData.StartPath();
|
||||||
AData.AddMoveToPath(x1, y1);
|
AData.AddMoveToPath(vx1, vy1);
|
||||||
AData.AddLineToPath(x2, y2);
|
AData.AddLineToPath(vx2, vy2);
|
||||||
AData.EndPath();
|
AData.EndPath();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -626,6 +645,7 @@ procedure TvSVGVectorialReader.ReadPathFromNode(ANode: TDOMNode;
|
|||||||
var
|
var
|
||||||
lNodeName, lStyleStr, lDStr: WideString;
|
lNodeName, lStyleStr, lDStr: WideString;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
lTmpPen: TvEntityWithPen;
|
||||||
begin
|
begin
|
||||||
for i := 0 to ANode.Attributes.Length - 1 do
|
for i := 0 to ANode.Attributes.Length - 1 do
|
||||||
begin
|
begin
|
||||||
@ -638,6 +658,14 @@ begin
|
|||||||
|
|
||||||
AData.StartPath();
|
AData.StartPath();
|
||||||
ReadPathFromString(UTF8Encode(lDStr), AData, ADoc);
|
ReadPathFromString(UTF8Encode(lDStr), AData, ADoc);
|
||||||
|
// Add the pen
|
||||||
|
lTmpPen := TvEntityWithPen.Create;
|
||||||
|
ReadSVGStyle(lStyleStr, lTmpPen);
|
||||||
|
AData.SetPenColor(lTmpPen.Pen.Color);
|
||||||
|
AData.SetPenStyle(lTmpPen.Pen.Style);
|
||||||
|
AData.SetPenWidth(lTmpPen.Pen.Width);
|
||||||
|
lTmpPen.Free;
|
||||||
|
//
|
||||||
AData.EndPath();
|
AData.EndPath();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -749,9 +777,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ConvertSVGCoordinatesToFPVCoordinates(
|
ConvertSVGDeltaToFPVDelta(
|
||||||
AData, lx, ly, lRect.X, lRect.Y);
|
AData, lx, ly, lRect.X, lRect.Y);
|
||||||
ConvertSVGCoordinatesToFPVCoordinates(
|
ConvertSVGDeltaToFPVDelta(
|
||||||
AData, cx, cy, lRect.CX, lRect.CY);
|
AData, cx, cy, lRect.CX, lRect.CY);
|
||||||
|
|
||||||
AData.AddEntity(lRect);
|
AData.AddEntity(lRect);
|
||||||
|
Loading…
Reference in New Issue
Block a user