-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
Moved 4 Methods from Paragraph to OdfContent Appended AddTab, AddLineBreak and AddNBSpace (still some Todo there)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,13 +329,16 @@ TOdfElement = class(TDOMElement) | |
const Values: array of string); | ||
|
||
|
||
function AppendOdfElement(AType: TElementType): TOdfElement; | ||
function AppendOdfElement(AType: TElementType;AClass: TOdfElementClass): TOdfElement; overload; | ||
function AppendOdfElement(AType: TElementType; at: TAttributeType; | ||
AValue: string;AClass: TOdfElementClass): TOdfElement; | ||
function AppendOdfElement(AType: TElementType): TOdfElement; overload; | ||
function AppendOdfElement(AType: TElementType; at: TAttributeType; | ||
AValue: string): TOdfElement; | ||
function OdfGetFirstElement: TOdfElement; | ||
function HasOdfElement(AType: TElementType): boolean; | ||
|
||
function FindStyle(aName: String): TOdfElement; | ||
function Find(aName: String;recursive:boolean=false): TOdfElement; | ||
function GetAttribute(AType: TAttributeType): TDOMAttr; | ||
function GetAttributeString(AType: TAttributeType): String; | ||
function HasAttribute(AType: TAttributeType): boolean; | ||
|
@@ -517,7 +520,8 @@ TOdfDocument = class | |
property ManifestRdf: TDOMElement read FManifestRdf write FManifestRdf; | ||
end; | ||
|
||
|
||
{Foreward declaration} | ||
THyperLink=class; | ||
|
||
{ TOdfContent } | ||
|
||
|
@@ -529,23 +533,25 @@ TOdfContent = class(TOdfElement) | |
public | ||
//p1-6.1.1 | ||
Procedure AppendText(aText:String); | ||
function AddLineBreak: TOdfContent; | ||
function AddNBSpace(FontStyles: TFontStyles): TOdfContent; | ||
function AddTab(FontStyles: TFontStyles): TOdfContent; | ||
function AddSpan(AText: string; FontStyles: TFontStyles): TSpan;overload; | ||
function AddSpan(AText: string; aFont: TFont;const doc: TOdfDocument): TSpan; | ||
overload; | ||
function AddSpan(AText: string; aStyle: string): TSpan;overload; | ||
function AddLink(AText: string; FontStyles: TFontStyles;aBMName:string): THyperLink; | ||
function GetCharacterContent(Recursive: boolean = true): string; | ||
property TextContent read GetTextContent write OdfSetTextContent; | ||
end; | ||
|
||
THyperLink=class; | ||
{ TOdfParagraph } | ||
|
||
TOdfParagraph = class(TOdfContent) | ||
private | ||
|
||
public | ||
function AddSpan(AText: string; FontStyles: TFontStyles): TSpan;overload; | ||
function AddSpan(AText: string; aFont: TFont;const doc: TOdfDocument): TSpan; | ||
overload; | ||
function AddSpan(AText: string; aStyle: string): TSpan;overload; | ||
function AddBookmark(AText: string; FontStyles: TFontStyles;aBMName:string): TSpan; | ||
function AddLink(AText: string; FontStyles: TFontStyles;aBMName:string): THyperLink; | ||
function AddBookmark(AText: string; FontStyles: TFontStyles;aBMName:string): TSpan; | ||
end; | ||
|
||
|
||
|
@@ -924,28 +930,6 @@ constructor TOdfElementTypeSet.Create(EtArray: TElementTypeArray); | |
|
||
{ TOdfParagraph } | ||
|
||
function TOdfParagraph.AddSpan(AText: string; FontStyles: TFontStyles): TSpan; | ||
begin | ||
result:=TSpan.CreateSpan(self.OwnerDocument as TXMLDocument, AText); | ||
result.SetStyle(FontStyles); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfParagraph.AddSpan(AText: string; aFont: TFont; | ||
const doc: TOdfDocument): TSpan; | ||
begin | ||
result:=TSpan.CreateSpan(self.OwnerDocument as TXMLDocument, AText); | ||
result.SetStyle(doc,aFont); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfParagraph.AddSpan(AText: string; aStyle: string): TSpan; | ||
begin | ||
result:=TSpan.CreateSpan(self.OwnerDocument as TXMLDocument, AText); | ||
result.SetStyle(aStyle); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfParagraph.AddBookmark(AText: string; FontStyles: TFontStyles; | ||
aBMName: string): TSpan; | ||
begin | ||
|
@@ -954,14 +938,6 @@ function TOdfParagraph.AddBookmark(AText: string; FontStyles: TFontStyles; | |
AppendChild(result); | ||
end; | ||
|
||
function TOdfParagraph.AddLink(AText: string; FontStyles: TFontStyles; | ||
aBMName: string): THyperLink; | ||
begin | ||
result := THyperLink.CreateLink(self.OwnerDocument as TXMLDocument,AText,aBMName); | ||
result.SetStyle(FontStyles); | ||
AppendChild(result); | ||
end; | ||
|
||
{ TBookMark } | ||
|
||
class function TBookMark.CreateBookmark(doc: TXMLDocument; AText, | ||
|
@@ -1052,22 +1028,21 @@ procedure TSpan.SetStyle(const doc: TOdfDocument; aFont: TFont); | |
|
||
if aFont.name <> 'default' then | ||
begin | ||
lFontdcls := FFontFaceDecls.FindNode(afont.Name); | ||
if not assigned(lFontdcls) then | ||
begin | ||
lFontdcls := CreateOdfElement(oetStyleFontFace,oatStyleName,afont.Name); | ||
TOdfElement(lFontdcls).SetAttribute(oatSvgFontFamily,afont.Name.QuotedString('''')); | ||
FontFaceDecls.AppendChild(lFontdcls); | ||
end; | ||
lStyleprop.SetAttribute(oatStyleFontName,afont.Name) ; | ||
lFontdcls := TOdfElement(FFontFaceDecls).Find(afont.Name); | ||
if not assigned(lFontdcls) then | ||
begin | ||
lFontdcls := CreateOdfElement(oetStyleFontFace,oatStyleName,afont.Name); | ||
TOdfElement(lFontdcls).SetAttribute(oatSvgFontFamily,afont.Name.QuotedString('''')); | ||
FontFaceDecls.AppendChild(lFontdcls); | ||
end; | ||
lStyleprop.SetAttribute(oatStyleFontName,afont.Name) ; | ||
end; | ||
if afont.Color <>clDefault then | ||
begin | ||
RedGreenBlue(afont.Color,lR,lG,lB); | ||
lStyleprop.SetAttribute(oatFoColor,'#'+IntToHex(Integer(RGBToColor(lb,lg,lr)),6)) ; | ||
|
||
end; | ||
if afont.Size>0 then | ||
if afont.Size>0 then //Todo -ojc: Handling of negative font-sizes | ||
lStyleprop.SetAttribute(oatFoFontSize,inttostr(afont.Size)+'pt') ; | ||
if aFont.Bold then | ||
lStyleprop.SetAttribute(oatFoFontWeight,OdfFontWeightValues[fwBold]); | ||
|
@@ -1148,6 +1123,51 @@ procedure TOdfContent.AppendText(aText: String); | |
until (et = oetNone) and (s=''); | ||
end; | ||
|
||
function TOdfContent.AddLineBreak: TOdfContent; | ||
begin | ||
result := TOdfContent(AppendOdfElement(oetTextLineBreak,TOdfContent)); | ||
end; | ||
|
||
function TOdfContent.AddNBSpace(FontStyles: TFontStyles): TOdfContent; | ||
begin | ||
result := AddSpan('',FontStyles); | ||
end; | ||
|
||
function TOdfContent.AddTab(FontStyles: TFontStyles): TOdfContent; | ||
begin | ||
result := TOdfContent(AppendOdfElement(oetTextTab,TOdfContent)); | ||
end; | ||
|
||
function TOdfContent.AddSpan(AText: string; FontStyles: TFontStyles): TSpan; | ||
begin | ||
result:=TSpan.CreateSpan(self.OwnerDocument as TXMLDocument, AText); | ||
result.SetStyle(FontStyles); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfContent.AddSpan(AText: string; aFont: TFont; | ||
const doc: TOdfDocument): TSpan; | ||
begin | ||
result:=TSpan.CreateSpan(self.OwnerDocument as TXMLDocument, AText); | ||
result.SetStyle(doc,aFont); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfContent.AddSpan(AText: string; aStyle: string): TSpan; | ||
begin | ||
result:=TSpan.CreateSpan(self.OwnerDocument as TXMLDocument, AText); | ||
result.SetStyle(aStyle); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfContent.AddLink(AText: string; FontStyles: TFontStyles; | ||
aBMName: string): THyperLink; | ||
begin | ||
result := THyperLink.CreateLink(self.OwnerDocument as TXMLDocument,AText,aBMName); | ||
result.SetStyle(FontStyles); | ||
AppendChild(result); | ||
end; | ||
|
||
function TOdfContent.GetCharacterContent(Recursive: boolean): string; | ||
var | ||
n: TDOMNode; | ||
|
@@ -1305,7 +1325,7 @@ function TOdfTextDocument.AddHeadline(aLevel: integer): TOdfContent; | |
result.SetAttribute(oatTextOutlineLevel, Inttostr(aLevel)); | ||
FText.AppendChild(result); | ||
|
||
lParaStyle:= TOdfElement(FStyles).FindStyle(CStyleTextBody) ; | ||
lParaStyle:= TOdfElement(FStyles).Find(CStyleTextBody) ; | ||
if not assigned(lParaStyle) then | ||
begin | ||
vStyle:=CreateOdfElement(oetStyleStyle); | ||
|
@@ -1321,7 +1341,7 @@ function TOdfTextDocument.AddHeadline(aLevel: integer): TOdfContent; | |
|
||
end; | ||
|
||
lParaStyle:= TOdfElement(FStyles).FindStyle(CStyleHeadingStb+Inttostr(aLevel)) ; | ||
lParaStyle:= TOdfElement(FStyles).Find(CStyleHeadingStb+Inttostr(aLevel)) ; | ||
if not assigned(lParaStyle) then | ||
begin | ||
vStyle:=CreateOdfElement(oetStyleStyle); | ||
|
@@ -1478,17 +1498,29 @@ class procedure TOdfElement.SetAttributes(atts: array of TAttributeType; | |
end; | ||
end; | ||
|
||
function TOdfElement.AppendOdfElement(AType: TElementType; | ||
AClass: TOdfElementClass): TOdfElement; | ||
begin | ||
result:=CreateOdfElement(AType,AClass, self.OwnerDocument as TXMLDocument); | ||
self.AppendChild(result); | ||
end; | ||
|
||
function TOdfElement.AppendOdfElement(AType: TElementType; at: TAttributeType; | ||
AValue: string; AClass: TOdfElementClass): TOdfElement; | ||
begin | ||
result:=AppendOdfElement(AType,AClass); | ||
result.SetAttribute(at, AValue); | ||
end; | ||
|
||
function TOdfElement.AppendOdfElement(AType: TElementType): TOdfElement; | ||
begin | ||
result:=CreateOdfElement(AType, self.OwnerDocument as TXMLDocument); | ||
self.AppendChild(result); | ||
result:=AppendOdfElement(AType,TOdfElement); | ||
end; | ||
|
||
function TOdfElement.AppendOdfElement(AType: TElementType; at: TAttributeType; | ||
AValue: string): TOdfElement; | ||
begin | ||
result:=AppendOdfElement(AType); | ||
result.SetAttribute(at, AValue); | ||
result:=AppendOdfElement(AType,at,AValue,TOdfElement); | ||
end; | ||
|
||
function TOdfElement.OdfGetFirstElement: TOdfElement; | ||
|
@@ -1527,23 +1559,39 @@ function TOdfElement.HasOdfElement(AType: TElementType): boolean; | |
end; | ||
end; | ||
|
||
function TOdfElement.FindStyle(aName: String): TOdfElement; | ||
function TOdfElement.Find(aName: String; recursive: boolean): TOdfElement; | ||
var | ||
lChlds: TDOMNode; | ||
lChlds, lNext: TDOMNode; | ||
begin | ||
lChlds := FirstChild; | ||
lNext:= GetNextNodeSkipChildren; | ||
result := nil; | ||
while assigned(lChlds) do | ||
while assigned(lChlds) and (lChlds<>lNext) do | ||
begin | ||
if not (lChlds is TDOMElement) | ||
then | ||
raise Exception.Create('Unexpected Node Type: ' + lChlds.ClassName); | ||
|
||
if (TOdfStyleStyle(lChlds).OdfStyleName=aname) | ||
{for some reason lChlds.inheritsfrom(TOdfStyleStyle)=False !} | ||
if (TOdfElement(lChlds).GetAttributeString(oatStyleName)=aName) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joecare99
via email
Author
Contributor
|
||
then | ||
exit(TOdfElement(lChlds)); | ||
|
||
lChlds:=lChlds.GetNextNodeSkipChildren; | ||
if (TOdfElement(lChlds).GetAttributeString(oatFoFontFamily)=aName) | ||
then | ||
exit(TOdfElement(lChlds)); | ||
|
||
{for some reason lChlds.inheritsfrom(TOdfContent)=False !} | ||
if (TOdfElement(lChlds).GetAttributeString(oatTextStyleName)=aName) | ||
then | ||
exit(TOdfElement(lChlds)); | ||
|
||
|
||
if recursive | ||
then | ||
lChlds:=lChlds.GetNextNode | ||
else | ||
lChlds:=lChlds.GetNextNodeSkipChildren; | ||
end; | ||
end; | ||
|
||
|
@@ -1739,7 +1787,6 @@ class function TOdfDocument.ParseXmlFile(AStream: TStream): TXMLDocument; | |
begin | ||
try | ||
Src:=TXMLInputSource.Create(AStream); | ||
|
||
Parser := TDOMParser.Create; | ||
Parser.Options.Namespaces:=True; | ||
Parser.Options.IgnoreComments:=True; | ||
|
@@ -2656,10 +2703,6 @@ function TOdfDocument.CreateSpan(AText: string; FontStyles: TFontStyles): TSpan; | |
result.SetStyle(FontStyles); | ||
end; | ||
|
||
|
||
|
||
|
||
|
||
{ TODO : Create a SiblingNode Parameter. | ||
If assigned the method will begin the search using it as a starting point, | ||
a context node. } | ||
|
I don't understand why do you insist with the generic name "Find" when the function has code that is specific to Find Styles.