fpvectorial-svg: Improves rectangle positioning

git-svn-id: trunk@45165 -
This commit is contained in:
sekelsenmat 2014-05-25 08:16:18 +00:00
parent 384e900260
commit f767727da8
2 changed files with 51 additions and 26 deletions

View File

@ -3565,7 +3565,7 @@ begin
ALeft := X;
ARight := X + CX;
ATop := Y;
ABottom := Y + CY;
ABottom := Y - CY;
end;
procedure TvRectangle.Render(ADest: TFPCustomCanvas; ARenderInfo: TvRenderInfo; ADestX: Integer;
@ -6199,13 +6199,14 @@ begin
if MinY = MaxY then MaxY := MinY + Height;
lLeft := CoordToCanvasX(MinX);
lTop := CoordToCanvasY(MinY);
lTop := CoordToCanvasY(MaxY);
lRight := CoordToCanvasX(MaxX);
lBottom := CoordToCanvasY(MaxY);
lBottom := CoordToCanvasY(MinY);
ADest.Brush.Style := bsClear;
ADest.Pen.FPColor := colBlack;
ADest.Pen.Style := psSolid;
ADest.Pen.Width := 1;
ADest.Rectangle(lLeft, lTop, lRight, lBottom);
end;

View File

@ -79,7 +79,7 @@ type
function DebugOutTokensAsString: string;
end;
TSVGCoordinateKind = (sckUnknown, sckX, sckY, sckYDelta);
TSVGCoordinateKind = (sckUnknown, sckX, sckY, sckXDelta, sckYDelta, sckYSize);
TSVGUnit = (suPX, suMM);
@ -135,10 +135,16 @@ type
function StringFloatZeroToOneToWord(AStr: string): Word;
procedure ConvertSVGCoordinatesToFPVCoordinates(
const AData: TvVectorialPage;
const ASrcX, ASrcY: Double; var ADestX, ADestY: Double);
const ASrcX, ASrcY: Double; var ADestX, ADestY: Double;
ADoViewBoxAdjust: Boolean = True);
procedure ConvertSVGDeltaToFPVDelta(
const AData: TvVectorialPage;
const ASrcX, ASrcY: Double; var ADestX, ADestY: Double);
const ASrcX, ASrcY: Double; var ADestX, ADestY: Double;
ADoViewBoxAdjust: Boolean = True);
procedure ConvertSVGSizeToFPVSize(
const AData: TvVectorialPage;
const ASrcX, ASrcY: Double; var ADestX, ADestY: Double;
ADoViewBoxAdjust: Boolean = True);
procedure AutoDetectDocSize(var ALeft, ATop, ARight, ABottom: Double; ABaseNode: TDOMNode);
function SVGColorValueStrToWord(AStr: string): Word;
public
@ -2385,9 +2391,9 @@ begin
ConvertSVGCoordinatesToFPVCoordinates(
AData, lx, ly, lRect.X, lRect.Y);
ConvertSVGDeltaToFPVDelta(
ConvertSVGSizeToFPVSize(
AData, cx, cy, lRect.CX, lRect.CY);
ConvertSVGDeltaToFPVDelta(
ConvertSVGSizeToFPVSize(
AData, lrx, lry, lRect.RX, lRect.RY);
lRect.RX := Abs(lRect.RX) * 2;
lRect.RY := Abs(lRect.RY) * 2;
@ -2677,6 +2683,21 @@ end;
function TvSVGVectorialReader.StringWithUnitToFloat(AStr: string;
ACoordKind: TSVGCoordinateKind = sckUnknown; ADefaultUnit: TSVGUnit = suPX): Double;
procedure DoViewBoxAdjust();
begin
if ViewBoxAdjustment then
begin
case ACoordKind of
sckX: Result := (Result - ViewBox_Left) * Page_Width / ViewBox_Width;
sckXDelta: Result := Result * Page_Width / ViewBox_Width;
sckY: Result := Page_Height - (Result - ViewBox_Top) * Page_Height / ViewBox_Height;
sckYDelta: Result := - (Result - ViewBox_Top) * Page_Height / ViewBox_Height;
sckYSize: Result := Result * Page_Height / ViewBox_Height;
end;
end;
end;
var
UnitStr, ValueStr: string;
Len: Integer;
@ -2702,12 +2723,7 @@ begin
begin
ValueStr := Copy(AStr, 1, Len-2);
Result := StrToFloat(ValueStr, FPointSeparator);
if ViewBoxAdjustment and (ACoordKind = sckX) then
Result := (Result - ViewBox_Left) * Page_Width / ViewBox_Width;
if ViewBoxAdjustment and (ACoordKind = sckY) then
Result := Page_Height - (Result - ViewBox_Top) * Page_Height / ViewBox_Height;
if ViewBoxAdjustment and (ACoordKind = sckYDelta) then
Result := - (Result - ViewBox_Top) * Page_Height / ViewBox_Height;
DoViewBoxAdjust();
end
else if LastChar = '%' then
begin
@ -2726,12 +2742,7 @@ begin
else // If there is no unit, just use StrToFloat
begin
Result := StrToFloat(AStr, FPointSeparator);
if ViewBoxAdjustment and (ACoordKind = sckX) then
Result := (Result - ViewBox_Left) * Page_Width / ViewBox_Width;
if ViewBoxAdjustment and (ACoordKind = sckY) then
Result := Page_Height - (Result - ViewBox_Top) * Page_Height / ViewBox_Height;
if ViewBoxAdjustment and (ACoordKind = sckYDelta) then
Result := - (Result - ViewBox_Top) * Page_Height / ViewBox_Height;
DoViewBoxAdjust();
end;
end;
@ -2742,30 +2753,43 @@ end;
procedure TvSVGVectorialReader.ConvertSVGCoordinatesToFPVCoordinates(
const AData: TvVectorialPage; const ASrcX, ASrcY: Double;
var ADestX,ADestY: Double);
var ADestX,ADestY: Double; ADoViewBoxAdjust: Boolean = True);
begin
ADestX := ASrcX * FLOAT_MILIMETERS_PER_PIXEL;
ADestY := AData.Height - ASrcY * FLOAT_MILIMETERS_PER_PIXEL;
if ViewBoxAdjustment then
if ViewBoxAdjustment and ADoViewBoxAdjust then
begin
ADestX := ASrcX * Page_Width / ViewBox_Width;
ADestY := AData.Height - ASrcY * Page_Height / ViewBox_Height;
ADestX := (ASrcX - ViewBox_Left) * Page_Width / ViewBox_Width;
ADestY := AData.Height - (ASrcY - ViewBox_Top) * Page_Height / ViewBox_Height;
end;
end;
procedure TvSVGVectorialReader.ConvertSVGDeltaToFPVDelta(
const AData: TvVectorialPage; const ASrcX, ASrcY: Double; var ADestX,
ADestY: Double);
ADestY: Double; ADoViewBoxAdjust: Boolean = True);
begin
ADestX := ASrcX * FLOAT_MILIMETERS_PER_PIXEL;
ADestY := - ASrcY * FLOAT_MILIMETERS_PER_PIXEL;
if ViewBoxAdjustment then
if ViewBoxAdjustment and ADoViewBoxAdjust then
begin
ADestX := ASrcX * Page_Width / ViewBox_Width;
ADestY := - ASrcY * Page_Height / ViewBox_Height;
end;
end;
procedure TvSVGVectorialReader.ConvertSVGSizeToFPVSize(
const AData: TvVectorialPage; const ASrcX, ASrcY: Double; var ADestX,
ADestY: Double; ADoViewBoxAdjust: Boolean = True);
begin
ADestX := ASrcX * FLOAT_MILIMETERS_PER_PIXEL;
ADestY := ASrcY * FLOAT_MILIMETERS_PER_PIXEL;
if ViewBoxAdjustment and ADoViewBoxAdjust then
begin
ADestX := ASrcX * Page_Width / ViewBox_Width;
ADestY := ASrcY * Page_Height / ViewBox_Height;
end;
end;
procedure TvSVGVectorialReader.AutoDetectDocSize(var ALeft, ATop, ARight, ABottom: Double;
ABaseNode: TDOMNode);
var