소스 검색

* Initial support for images

git-svn-id: trunk@11155 -
michael 17 년 전
부모
커밋
9111ea4da6
2개의 변경된 파일71개의 추가작업 그리고 5개의 파일을 삭제
  1. 47 1
      utils/fpdoc/dw_html.pp
  2. 24 4
      utils/fpdoc/dwriter.pp

+ 47 - 1
utils/fpdoc/dw_html.pp

@@ -110,6 +110,7 @@ type
     FDateFormat: String;
     FIndexColCount : Integer;
     FSearchPage : String;
+    FBaseImageURL : String;
     function ResolveLinkID(const Name: String): DOMString;
     function ResolveLinkIDInUnit(const Name,UnitName: String): DOMString;
     function ResolveLinkWithinPackage(AElement: TPasElement;
@@ -141,6 +142,7 @@ type
     procedure DescrEndItalic; override;
     procedure DescrBeginEmph; override;
     procedure DescrEndEmph; override;
+    procedure DescrWriteImageEl(const AFileName, ACaption : DOMString); override;
     procedure DescrWriteFileEl(const AText: DOMString); override;
     procedure DescrWriteKeywordEl(const AText: DOMString); override;
     procedure DescrWriteVarEl(const AText: DOMString); override;
@@ -257,6 +259,7 @@ type
     property OnTest: TNotifyEvent read FOnTest write SetOnTest;
     Property CharSet : String Read FCharSet Write FCharSet;
     Property IndexColCount : Integer Read FIndexColCount write FIndexColCount;
+    Property BaseImageURL : String Read FBaseImageURL Write FBaseImageURL;
   end;
 
   THTMWriter = class(THTMLWriter)
@@ -959,6 +962,47 @@ begin
   PopOutputNode;
 end;
 
+procedure THTMLWriter.DescrWriteImageEl(const AFileName, ACaption : DOMString);
+
+Var
+  Pel,Cel : TDOMNode;
+  El :TDomElement;
+  D : String;
+  L : Integer;
+   
+begin
+  // Determine parent node.
+  If (ACaption='') then
+    Pel:=CurOutputNode
+  else
+    begin
+    Cel:=CreateTable(CurOutputNode);
+    Pel:=CreateTD(CreateTR(Cel));
+    AppendText(CreateTD(CreateTR(Cel)),ACaption);
+    end;
+  // Determine URL for image.  
+  D:=BaseImageURL;
+  If (D='') then
+    begin
+    If (Module=Nil) then
+      D:=Allocator.GetRelativePathToTop(Package)
+    else 
+      D:=Allocator.GetRelativePathToTop(Module);
+    L:=Length(D);  
+    If (L>0) and (D[L]<>'/') then
+      D:=D+'/';
+    D:=D+'images/';
+    end
+  else  
+    L:=Length(D);  
+    If (L>0) and (D[L]<>'/') then
+      D:=D+'/';
+  // Create image node.  
+  El:=CreateEl(Pel,'img');
+  EL['src']:=D+AFileName;
+  El['alt']:=ACaption;
+end;
+
 procedure THTMLWriter.DescrWriteFileEl(const AText: DOMString);
 var
   NewEl: TDOMElement;
@@ -2126,6 +2170,7 @@ begin
   For C:='A' to 'Z' do
     Lists[C]:=Nil;
   L.Sort;
+  Cl:=Nil;
   // Divide over alphabet
   For I:=0 to L.Count-1 do
     begin
@@ -2142,7 +2187,8 @@ begin
           Lists[C]:=CL;
           end;
         end;
-      CL.AddObject(S,E);
+      if assigned(cl) then  
+        CL.AddObject(S,E);
       end;  
     end;  
   Try  

+ 24 - 4
utils/fpdoc/dwriter.pp

@@ -69,10 +69,10 @@ type
   private
     FEngine  : TFPDocEngine;
     FPackage : TPasPackage;
-
     FTopics  : TList;
+    FImgExt : String;
+    
   protected
-
     procedure Warning(AContext: TPasElement; const AMsg: String);
     procedure Warning(AContext: TPasElement; const AMsg: String;
       const Args: array of const);
@@ -96,7 +96,8 @@ type
       Node: TDOMNode);
     function ConvertSimpleBlock(AContext: TPasElement; Node: TDOMNode): Boolean;
     Function FindTopicElement(Node : TDocNode): TTopicElement;
-
+    Procedure ConvertImage(El : TDomElement);
+    
     procedure DescrWriteText(const AText: DOMString); virtual; abstract;
     procedure DescrBeginBold; virtual; abstract;
     procedure DescrEndBold; virtual; abstract;
@@ -104,6 +105,7 @@ type
     procedure DescrEndItalic; virtual; abstract;
     procedure DescrBeginEmph; virtual; abstract;
     procedure DescrEndEmph; virtual; abstract;
+    procedure DescrWriteImageEl(const AFileName, ACaption : DOMString); virtual; abstract;
     procedure DescrWriteFileEl(const AText: DOMString); virtual; abstract;
     procedure DescrWriteKeywordEl(const AText: DOMString); virtual; abstract;
     procedure DescrWriteVarEl(const AText: DOMString); virtual; abstract;
@@ -148,6 +150,7 @@ type
     property Engine : TFPDocEngine read FEngine;
     Property Package : TPasPackage read FPackage;
     Property Topics : TList Read FTopics;
+    Property ImageExtension : String Read FImgExt Write FImgExt;
     // Should return True if option was succesfully interpreted.
     Function InterpretOption(Const Cmd,Arg : String) : Boolean; Virtual;
     Class Procedure Usage(List : TStrings); virtual;
@@ -320,6 +323,7 @@ begin
   FEngine  := AEngine;
   FPackage := APackage;
   FTopics:=Tlist.Create;
+  FImgExt:='.png';
 end;
 
 destructor TFPDocWriter.Destroy;
@@ -971,10 +975,26 @@ begin
     ConvertDefinitionList;
     DescrEndDefinitionList;
     Result := True;
-  end else
+  end else if Node.NodeName = 'img' then
+  begin
+    ConvertImage(Node as TDomElement);
+  end else  
     Result := False;
 end;
 
+Procedure TFPDocWriter.ConvertImage(El : TDomElement);
+
+Var
+  FN,Cap : DOMString;
+
+begin
+  FN:=El['file'];
+  Cap:=El['caption'];
+  ChangeFileExt(FN,ImageExtension);
+  DescrWriteImageEl(FN,Cap);
+end;
+
+
 Constructor TTopicElement.Create(const AName: String; AParent: TPasElement);
 
 begin