fpvectorial: svg: Reworks the text span style stack system, now it shows the red in the new example

git-svn-id: trunk@44395 -
This commit is contained in:
sekelsenmat 2014-03-10 09:54:57 +00:00
parent 5d6b6286f1
commit bfe8c53b66
2 changed files with 59 additions and 7 deletions

View File

@ -104,6 +104,7 @@ type
TvPage = class;
TvVectorialPage = class;
TvTextPageSequence = class;
TvEntityWithPenBrushAndFont = class;
{ Pen, Brush and Font }
@ -192,6 +193,7 @@ type
procedure Clear(); virtual;
procedure CopyFrom(AFrom: TvStyle);
procedure ApplyOver(AFrom: TvStyle); virtual;
procedure ApplyIntoEntity(ADest: TvEntityWithPenBrushAndFont); virtual;
function CreateStyleCombinedWithParent: TvStyle;
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual;
end;
@ -1739,6 +1741,48 @@ begin
SetElements := AFrom.SetElements + SetElements;
end;
procedure TvStyle.ApplyIntoEntity(ADest: TvEntityWithPenBrushAndFont);
begin
if ADest = nil then Exit;
// Pen
if spbfPenColor in SetElements then
ADest.Pen.Color := Pen.Color;
if spbfPenStyle in SetElements then
ADest.Pen.Style := Pen.Style;
if spbfPenWidth in SetElements then
ADest.Pen.Width := Pen.Width;
// Brush
if spbfBrushColor in SetElements then
ADest.Brush.Color := Brush.Color;
if spbfBrushStyle in SetElements then
ADest.Brush.Style := Brush.Style;
{if spbfBrushGradient in SetElements then
Brush.Gra := AFrom.Brush.Style;}
// Font
if spbfFontColor in SetElements then
ADest.Font.Color := Font.Color;
if spbfFontSize in SetElements then
ADest.Font.Size := Font.Size;
if spbfFontName in SetElements then
ADest.Font.Name := Font.Name;
if spbfFontBold in SetElements then
ADest.Font.Bold := Font.Bold;
if spbfFontItalic in SetElements then
ADest.Font.Italic := Font.Italic;
If spbfFontUnderline in SetElements then
ADest.Font.Underline := Font.Underline;
If spbfFontStrikeThrough in SetElements then
ADest.Font.StrikeThrough := Font.StrikeThrough;
{If spbfAlignment in SetElements then
ADest.Alignment := Alignment; }
end;
function TvStyle.CreateStyleCombinedWithParent: TvStyle;
begin
Result := TvStyle.Create;
@ -3270,7 +3314,7 @@ function TvText.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc;
var
lStr: string;
begin
lStr := Format('[%s] Name=%s X=%f Y=%f Text="%s" Color=%s Size=%d Name=%s Orientation=%f Bold=%s Italic=%s Underline=%s StrikeThrough=%s TextAnchor=%s',
lStr := Format('[%s] Name=%s X=%f Y=%f Text="%s" [.Font=>] Color=%s Size=%d Name=%s Orientation=%f Bold=%s Italic=%s Underline=%s StrikeThrough=%s TextAnchor=%s',
[
Self.ClassName, Name, X, Y, Value.Text,
GenerateDebugStrForFPColor(Font.Color),

View File

@ -991,14 +991,17 @@ begin
// But sometimes SVG also uses stroke! Oh no...
else if AKey = 'stroke' then
begin
ADest.Font.Color := ReadSVGColor(AValue);
Result := Result + [spbfFontColor];
if lLowerValue <> 'none' then // sometimes we get a fill value, but a stroke=none after it...
begin
ADest.Font.Color := ReadSVGColor(AValue);
Result := Result + [spbfFontColor];
end;
end
else if AKey = 'fill-opacity' then
ADest.Font.Color.Alpha := StrToInt(AValue)*$101
else if AKey = 'font-size' then
begin
ADest.Font.Size := Round(StringWithUnitToFloat(AValue));
ADest.Font.Size := Round(StringWithUnitToFloat(AValue, sckX));
Result := Result + [spbfFontSize];
end
else if AKey = 'font-family' then
@ -1007,7 +1010,10 @@ begin
begin
case lLowerValue of
'bold': ADest.Font.Bold := True;
else
ADest.Font.Bold := False;
end;
Result := Result + [spbfFontBold];
end
// Other text attributes, non-font ones
else if AKey = 'text-anchor' then
@ -2389,7 +2395,6 @@ end;
function TvSVGVectorialReader.ReadTextFromNode(ANode: TDOMNode;
AData: TvVectorialPage; ADoc: TvVectorialDocument): TvEntity;
var
lTextStr: string = '';
lx, ly: double;
lText: TvText;
lParagraph: TvParagraph;
@ -2405,8 +2410,7 @@ var
for j := 0 to lTextSpanStack.GetList().Count-1 do
begin
lCurStyle := TSVGTextSpanStyle(lTextSpanStack.GetList().Items[j]);
if ADest.Style = nil then ADest.Style := TvStyle.Create;
ADest.Style.ApplyOver(lCurStyle);
lCurStyle.ApplyIntoEntity(ADest);
if lCurStyle.PositionSet then
begin
ADest.X := ADest.X + lCurStyle.X; // or substitute completely ?
@ -2617,6 +2621,10 @@ begin
begin
ValueStr := Copy(AStr, 1, Len-2);
Result := StrToFloat(ValueStr, FPointSeparator);
if ViewBoxAdjustment and (ACoordKind = sckX) then
Result := Result * Page_Width / ViewBox_Width;
if ViewBoxAdjustment and (ACoordKind = sckY) then
Result := Page_Height - Result * Page_Height / ViewBox_Height;
end
else if LastChar = '%' then
begin