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; TvPage = class;
TvVectorialPage = class; TvVectorialPage = class;
TvTextPageSequence = class; TvTextPageSequence = class;
TvEntityWithPenBrushAndFont = class;
{ Pen, Brush and Font } { Pen, Brush and Font }
@ -192,6 +193,7 @@ type
procedure Clear(); virtual; procedure Clear(); virtual;
procedure CopyFrom(AFrom: TvStyle); procedure CopyFrom(AFrom: TvStyle);
procedure ApplyOver(AFrom: TvStyle); virtual; procedure ApplyOver(AFrom: TvStyle); virtual;
procedure ApplyIntoEntity(ADest: TvEntityWithPenBrushAndFont); virtual;
function CreateStyleCombinedWithParent: TvStyle; function CreateStyleCombinedWithParent: TvStyle;
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual; function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual;
end; end;
@ -1739,6 +1741,48 @@ begin
SetElements := AFrom.SetElements + SetElements; SetElements := AFrom.SetElements + SetElements;
end; 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; function TvStyle.CreateStyleCombinedWithParent: TvStyle;
begin begin
Result := TvStyle.Create; Result := TvStyle.Create;
@ -3270,7 +3314,7 @@ function TvText.GenerateDebugTree(ADestRoutine: TvDebugAddItemProc;
var var
lStr: string; lStr: string;
begin 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, Self.ClassName, Name, X, Y, Value.Text,
GenerateDebugStrForFPColor(Font.Color), GenerateDebugStrForFPColor(Font.Color),

View File

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