From bfe8c53b6685c4d4fcb6fca790377f62eeaf15b2 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Mon, 10 Mar 2014 09:54:57 +0000 Subject: [PATCH] fpvectorial: svg: Reworks the text span style stack system, now it shows the red in the new example git-svn-id: trunk@44395 - --- components/fpvectorial/fpvectorial.pas | 46 ++++++++++++++++++- components/fpvectorial/svgvectorialreader.pas | 20 +++++--- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/components/fpvectorial/fpvectorial.pas b/components/fpvectorial/fpvectorial.pas index f5b9d68f68..9e2dd88dc2 100644 --- a/components/fpvectorial/fpvectorial.pas +++ b/components/fpvectorial/fpvectorial.pas @@ -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), diff --git a/components/fpvectorial/svgvectorialreader.pas b/components/fpvectorial/svgvectorialreader.pas index c04787e7c2..9bd12cdcd2 100644 --- a/components/fpvectorial/svgvectorialreader.pas +++ b/components/fpvectorial/svgvectorialreader.pas @@ -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