{Version 9.45} {*********************************************************} {* READHTML.PAS *} {* *} {* Thanks to Mike Lischke for his *} {* assistance with the Unicode conversion *} {* *} {*********************************************************} { Copyright (c) 1995-2008 by L. David Baldwin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Note that the source modules, HTMLGIF1.PAS, PNGZLIB1.PAS, DITHERUNIT.PAS, and URLCON.PAS are covered by separate copyright notices located in those modules. } {$i htmlcons.inc} { The Parser This module contains the parser which reads thru the document. It divides it into sections storing the pertinent information in Section objects. The document itself is then a TList of section objects. See the HTMLSubs unit for the definition of the section objects. Key Variables: Sy: An enumerated type which indicates what the current token is. For example, a value of TextSy would indicate a hunk of text, PSy that a

tag was encountered, etc. LCh: The next character in the stream to be analyzed. In mixed case. Ch: The same character in upper case. LCToken: A string which is associated with the current token. If Sy is TextSy, then LCToken contains the text. Attributes: A list of TAttribute's for tokens such as , , which have attributes. Section: The current section being built. SectionList: The list of sections which form the document. When in a Table, SectionList will contain the list that makes up the current cell. Key Routines: GetCh: Gets the next character from the stream. Fills Ch and LCh. Skips comments. Next: Gets the next token. Fills Sy, LCToken, Attributes. Calls GetCh so the next character after the present token is available. Each part of the parser is responsible for calling Next after it does its thing. } unit Readhtml; interface uses SysUtils, Classes, {$IFNDEF LCL} WinTypes, WinProcs, Messages, {$ELSE} LclIntf, LMessages, Types, LclType, HtmlMisc, {$ENDIF} Graphics, Controls, Dialogs, StdCtrls, HTMLUn2, StyleUn; type LoadStyleType = (lsFile, lsString, lsInclude); TIncludeType = procedure(Sender: TObject; const Command: string; Params: TStrings; var IString: string) of Object; TSoundType = procedure(Sender: TObject; const SRC: string; Loop: integer; Terminate: boolean) of Object; TMetaType = procedure(Sender: TObject; const HttpEq, Name, Content: string) of Object; TLinkType = procedure(Sender: TObject; const Rel, Rev, Href: string) of Object; TGetStreamEvent = procedure(Sender: TObject; const SRC: string; var Stream: TMemoryStream) of Object; {$IFNDEF LCL} TFrameViewerBase = class(TWinControl) {$ELSE} TFrameViewerBase = class(TCustomControl) {$ENDIF} private procedure wmerase(var msg:TMessage); message wm_erasebkgnd; protected FOnInclude: TIncludeType; FOnSoundRequest: TSoundType; FOnScript: TScriptEvent; FOnLink: TLinkType; procedure AddFrame(FrameSet: TObject; Attr: TAttributeList; const FName: string); virtual; abstract; function CreateSubFrameSet(FrameSet: TObject): TObject; virtual; abstract; procedure DoAttributes(FrameSet: TObject; Attr: TAttributeList); virtual; abstract; procedure EndFrameSet(FrameSet: TObject); virtual; abstract; end; TPropStack = class(TFreeList) private function GetProp(Index: integer): TProperties; public property AnItem[Index: integer]: TProperties read GetProp; default; function Last: TProperties; procedure Delete(Index: integer); end; var PropStack: TPropStack; Title: string; Base: string; BaseTarget: string; NoBreak: boolean; {set when in } procedure ParseHTMLString(const S: string; ASectionList: TList; AIncludeEvent: TIncludeType; ASoundEvent: TSoundType; AMetaEvent: TMetaType; ALinkEvent: TLinkType); procedure ParseTextString(const S: string; ASectionList: TList); procedure FrameParseString(FrameViewer: TFrameViewerBase; FrameSet: TObject; ALoadStyle: LoadStyleType; const FName, S: string; AMetaEvent: TMetaType); function IsFrameString(ALoadStyle: LoadStyleType; const FName, S : string; FrameViewer: TObject): boolean; function TranslateCharset(const Content: string; var Charset: TFontCharset): boolean; procedure InitializeFontSizes(Size: integer); function PushNewProp(const Tag, AClass, AnID, APseudo, ATitle: string; AProp: TProperties): boolean; procedure PopAProp(Tag: string); implementation uses htmlsubs, htmlsbs1, htmlview, StylePars, UrlSubs; Const Tab = #9; EofChar = #0; var Sy : Symb; Section : TSection; SectionList: TCellBasic; MasterList: TSectionList; CurrentURLTarget: TURLTarget; InHref: boolean; Attributes : TAttributeList; BaseFontSize: integer; InScript: boolean; {when in a