diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-10-12 09:11:57 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2011-02-03 15:33:43 +0200 |
commit | fa8acc2b58592ea1382ae8a986c3c159e53229ce (patch) | |
tree | f6c0f34143d471ff11287fd6d3c1c1e500b6948a /docview | |
parent | 1e649f145f5a0930755b24756081f7399ab2847f (diff) | |
download | fpGUI-fa8acc2b58592ea1382ae8a986c3c159e53229ce.tar.xz |
temp storage for Encoding implementation in DocView
Diffstat (limited to 'docview')
-rw-r--r-- | docview/components/richtext/CanvasFontManager.pas | 72 | ||||
-rw-r--r-- | docview/components/richtext/RichTextLayoutUnit.pas | 6 | ||||
-rw-r--r-- | docview/components/richtext/RichTextView.pas | 45 | ||||
-rw-r--r-- | docview/src/HelpFile.pas | 14 | ||||
-rw-r--r-- | docview/src/SettingsUnit.pas | 3 | ||||
-rw-r--r-- | docview/src/frm_main.pas | 49 |
6 files changed, 87 insertions, 102 deletions
diff --git a/docview/components/richtext/CanvasFontManager.pas b/docview/components/richtext/CanvasFontManager.pas index ed3abf08..063f759b 100644 --- a/docview/components/richtext/CanvasFontManager.pas +++ b/docview/components/richtext/CanvasFontManager.pas @@ -38,7 +38,6 @@ Type {Standard Font character Set} TFontCharSet=(fcsSBCS,fcsDBCS,fcsMBCS); {Single,Double,mixed Byte} - // a user-oriented specification of a font; not an actual structure in the INF file TFontSpec = record FaceName: string[ 64 ]; @@ -1070,70 +1069,17 @@ end; procedure TCanvasFontManager.DrawString(var Point: TPoint; const Length: longint; const S: PChar); var - t: string; - - // Seaches <AValue> and replaces <ADel> with <AIns>. Case sensitive. - function tiStrTran(AValue, ADel, AIns : string): string; - var - i : integer; - sToChange : string; - begin - result := ''; - sToChange := AValue; - i := UTF8Pos(ADel, sToChange); - while i <> 0 do - begin - result := result + UTF8Copy(sToChange, 1, i-1) + AIns; - UTF8Delete(sToChange, 1, i+UTF8length(ADel)-1); - i := UTF8Pos(ADel, sToChange); - end; - result := result + sToChange; - end; - + t: TfpgString; begin t := s; - -// Hack Alert #2: replace strange table chars with something we can actually see - //t := SubstituteChar(t, Chr(218), Char('+') ); // top-left corner - //t := SubstituteChar(t, Chr(196), Char('-') ); // horz row deviders - //t := SubstituteChar(t, Chr(194), Char('-') ); // centre top T connection - //t := SubstituteChar(t, Chr(191), Char('+') ); // top-right corner - //t := SubstituteChar(t, Chr(192), Char('+') ); // bot-left corner - //t := SubstituteChar(t, Chr(193), Char('-') ); // centre bottom inverted T - //t := SubstituteChar(t, Chr(197), Char('+') ); - //t := SubstituteChar(t, Chr(179), Char('|') ); // - //t := SubstituteChar(t, Chr(195), Char('|') ); - //t := SubstituteChar(t, Chr(180), Char('|') ); - //t := SubstituteChar(t, Chr(217), Char('+') ); // bot-right corner - - // it's cheaper to first check for the char than actually running full tiStrTran - // CodePage 437 (kind-of) to Unicode mapping - t := tiStrTran(t, Char(16), '>' ); - t := tiStrTran(t, Char(17), '<' ); - t := tiStrTran(t, Char($1f), '▼' ); -// if pos(t, Char(179)) > 0 then - t := tiStrTran(t, Char(179), '│' ); -// if pos(t, Char(180)) > 0 then - t := tiStrTran(t, Char(180), '┤' ); -// if pos(t, Char(191)) > 0 then - t := tiStrTran(t, Char(191), '┐' ); -// if pos(t, Char(192)) > 0 then - t := tiStrTran(t, Char(192), '└' ); -// if pos(t, Char(193)) > 0 then - t := tiStrTran(t, Char(193), '┴' ); -// if pos(t, Char(194)) > 0 then - t := tiStrTran(t, Char(194), '┬' ); -// if pos(t, Char(195)) > 0 then - t := tiStrTran(t, Char(195), '├' ); -// if pos(t, Char(196)) > 0 then - t := tiStrTran(t, Char(196), '─' ); -// if pos(t, Char(197)) > 0 then - t := tiStrTran(t, Char(197), '┼' ); -// if pos(t, Char(217)) > 0 then - t := tiStrTran(t, Char(217), '┘' ); -// if pos(t, Char(218)) > 0 then - t := tiStrTran(t, Char(218), '┌' ); - + //case Settings.Encoding of + // encUTF8: t := IPFToUTF8(t); + // encCP437: t := CP437ToUTF8(t); + // encCP850: t := CP850ToUTF8(t); + // encIBMGraph: t := IBMGraphToUTF8(t); + //else + // t := IPFToUTF8(t); + //end; FCanvas.DrawString(Point.X, Point.Y, t); Point.x := Point.X + Canvas.Font.TextWidth(t); end; diff --git a/docview/components/richtext/RichTextLayoutUnit.pas b/docview/components/richtext/RichTextLayoutUnit.pas index 9b684349..61ce150c 100644 --- a/docview/components/richtext/RichTextLayoutUnit.pas +++ b/docview/components/richtext/RichTextLayoutUnit.pas @@ -437,7 +437,7 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>'); if not FFontManager.IsFixed then begin // end of italic; add a space - inc( WordX, FFontManager.CharWidth( ' ' ) ); +// inc( WordX, FFontManager.CharWidth( ' ' ) ); end; end; @@ -706,7 +706,7 @@ begin and ( faItalic in Style.Font.Attributes ) and ( not FFontManager.IsFixed ) then // end of italic; add a space - inc( X, FFontManager.CharWidth( ' ' ) ); +// inc( X, FFontManager.CharWidth( ' ' ) ); PerformStyleTag( Element.Tag, Style, @@ -783,7 +783,7 @@ begin and ( faItalic in Style.Font.Attributes ) and ( not FFontManager.IsFixed ) then // end of italic; add a space - inc( X, FFontManager.CharWidth( ' ' ) ); +// inc( X, FFontManager.CharWidth( ' ' ) ); PerformStyleTag( Element.Tag, Style, diff --git a/docview/components/richtext/RichTextView.pas b/docview/components/richtext/RichTextView.pas index e32c71ee..5e518d78 100644 --- a/docview/components/richtext/RichTextView.pas +++ b/docview/components/richtext/RichTextView.pas @@ -41,6 +41,9 @@ Type TScrollingDirection = ( sdUp, sdDown ); +var + testvar: integer = 0; + Type TRichTextView = class; @@ -408,6 +411,8 @@ uses ,nvUtilities ,RichTextDocumentUnit ,RichTextDisplayUnit + ,fpg_stringutils + ,SettingsUnit // TODO: We shouldn't have this dependency!! ; Procedure TRichTextView.SetSelectionStart( SelectionStart: longint ); @@ -503,7 +508,6 @@ var StartLine: longint; EndLine: longint; begin - if SelectionSet then begin OldClip := Canvas.GetClipRect; @@ -768,9 +772,10 @@ var begin inherited HandleLMouseDown(x, y, shiftstate); Offset := 0; + testvar := 1; Position := FindPoint( X, Y, Line, Offset, Link ); FClickedLink := Link; -// writeln('Pos=', Ord(Position), ' link=', Link); + writeln(' link=', Link, ' line=', Line, ' offset=', offset); if Position in [tpAboveTextArea, tpBelowTextArea] then // not on the control (this probably won't happen) @@ -1100,6 +1105,9 @@ function TRichTextView.FindPoint( XToFind: longint; var TextHeight: longint; begin + if testvar = 1 then + testvar := 0; + LineIndex := 0; Offset := 0; Link := ''; @@ -1642,31 +1650,8 @@ end; // ADelay = True means that we hold off on redoing the Layout and Painting. Procedure TRichTextView.AddText( Text: PChar; ADelay: boolean ); -var - s: string; begin - s := Text; - // Warning: Hack Alert! replace some strange Bell character found in some INF files -// s := SubstituteChar(s, Chr($07), Chr($20) ); - s := StringReplace(s, Chr($07), #$E2#$80#$A2, [rfReplaceAll, rfIgnoreCase]); // u+2022 small bullet - -//// Hack Alert #2: replace strange table chars with something we can actually see -// s := SubstituteChar(s, Chr(218), Char('+') ); // top-left corner -// s := SubstituteChar(s, Chr(196), Char('-') ); // horz row deviders -// s := SubstituteChar(s, Chr(194), Char('-') ); // centre top T connection -// s := SubstituteChar(s, Chr(191), Char('+') ); // top-right corner -// s := SubstituteChar(s, Chr(192), Char('+') ); // bot-left corner -// s := SubstituteChar(s, Chr(193), Char('-') ); // centre bottom inverted T -// s := SubstituteChar(s, Chr(197), Char('+') ); -// s := SubstituteChar(s, Chr(179), Char('|') ); // -// s := SubstituteChar(s, Chr(195), Char('|') ); -// s := SubstituteChar(s, Chr(180), Char('|') ); -// s := SubstituteChar(s, Chr(217), Char('+') ); // bot-right corner - - - - - AddAndResize( FText, PChar(s) ); + AddAndResize( FText, Text); if not ADelay then begin Layout; @@ -2110,6 +2095,9 @@ begin FCursorOffset := Offset; FCursorRow := Row; Index := FLayout.GetCharIndex( FLayout.FLines^[ Row ].Text ) + Offset; + + writeln(' SetCursorPosition: offset=', FCursorOffset, ' row=', FCursorRow, ' index=', Index); + exit; if PreserveSelection then begin SetSelectionEndInternal( Index ) @@ -2790,6 +2778,11 @@ begin end else begin + writeln('need to scroll down, desired row below bottom line'); + writeln('BottomLine = ', BottomLine, ' Row = ', Row); + writeln('new pos = ', FLayout.GetLinePosition( Row ) + + FLayout.FLines^[ Row ].Height + - GetTextAreaHeight); // need to scroll down, desired row below bottom line if ( BottomLine <> -1 ) and ( Row >= BottomLine ) then diff --git a/docview/src/HelpFile.pas b/docview/src/HelpFile.pas index dc9998ed..f7e436fe 100644 --- a/docview/src/HelpFile.pas +++ b/docview/src/HelpFile.pas @@ -18,6 +18,9 @@ uses type + TFontEncoding = (encUTF8, encCP437, encCP850, encIBMGraph); + + TIndexEntry = class(TObject) private name: String; @@ -46,8 +49,6 @@ type end; - { THelpFile } - THelpFile = class(TObject) private function GetFormatVersion: string; @@ -172,7 +173,7 @@ type procedure SetupFontSubstitutes( Substitutions: string ); public NotesLoaded: boolean; // used externally - + Encoding: TFontEncoding; end; // Returns helpfile that the given topic is within @@ -397,9 +398,9 @@ begin LogEvent(LogParse, 'Helpfile Load: ' + aFileName); _FileName := aFileName; + Encoding := encUTF8; InitMembers; - Open; // we always need these basics: @@ -414,7 +415,6 @@ begin Close; raise; end; - // the rest is loaded on demand end; @@ -1060,6 +1060,10 @@ begin begin pFontSpec := p + i * sizeof( THelpFontSpec ); _FontTable.Add( pFontSpec ); + if pFontSpec^.CodePage = 850 then + Encoding := encCP850 + else if pFontSpec^.CodePage = 437 then + Encoding := encCP437; end; end; diff --git a/docview/src/SettingsUnit.pas b/docview/src/SettingsUnit.pas index e100b1b1..77c72cce 100644 --- a/docview/src/SettingsUnit.pas +++ b/docview/src/SettingsUnit.pas @@ -13,6 +13,7 @@ Uses ,fpg_base ,fpg_main ,CanvasFontManager + ,HelpFile ; Const @@ -94,6 +95,7 @@ Type GlobalSearchLocation: TGlobalSearchLocation; SearchDirectories: TStringList; IPFTopicSaveAsEscaped: boolean; + Encoding: TFontEncoding; end; @@ -276,6 +278,7 @@ begin else GlobalSearchLocation := gsCustom; + Encoding := encUTF8; end; end; LogEvent(LogSettings, ' Done' ); diff --git a/docview/src/frm_main.pas b/docview/src/frm_main.pas index f1b4284c..4fc35709 100644 --- a/docview/src/frm_main.pas +++ b/docview/src/frm_main.pas @@ -8,7 +8,7 @@ uses SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_panel, fpg_tab, fpg_tree, fpg_splitter, fpg_menu, fpg_button, fpg_listbox, fpg_label, fpg_edit, fpg_radiobutton, fpg_progressbar, fpg_imagelist, - fpg_imgfmt_bmp, + fpg_imgfmt_bmp, fpg_combobox, HelpFile, RichTextView, HelpTopic; type @@ -71,6 +71,7 @@ type btnQuit: TfpgButton; Bevel1: TfpgBevel; Bevel2: TfpgBevel; + cbEncoding: TfpgComboBox; Bevel3: TfpgBevel; btnTBNoteAdd: TfpgButton; {@VFD_HEAD_END: MainForm} @@ -151,7 +152,9 @@ type procedure lbHistoryDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); procedure lbHistoryKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); procedure btnSearchClicked(Sender: TObject); + procedure cbEncodingChanged(Sender: TObject); procedure btnNotesGotoClicked(Sender: TObject); + procedure UpdateEncodingComboBox; procedure IndexSearchEditOnChange(Sender: TObject); procedure DisplaySelectedSearchResultTopic; procedure NavigateToHistoryIndex(AIndex: integer); @@ -1003,11 +1006,22 @@ begin DoSearch; end; +procedure TMainForm.cbEncodingChanged(Sender: TObject); +begin + Settings.Encoding := TFontEncoding(cbEncoding.FocusItem); + DisplayTopic(CurrentTopic); +end; + procedure TMainForm.btnNotesGotoClicked(Sender: TObject); begin GotoCurrentNote; end; +procedure TMainForm.UpdateEncodingComboBox; +begin + cbEncoding.FocusItem := Ord(Settings.Encoding); +end; + procedure TMainForm.IndexSearchEditOnChange(Sender: TObject); var tmpMatchIndex: longint; @@ -1364,9 +1378,8 @@ begin HelpFile := THelpFile.Create( FileName ); if Settings.FixedFontSubstitution then HelpFile.SetupFontSubstitutes( Settings.FixedFontSubstitutes ); - + Settings.Encoding := HelpFile.Encoding; aHelpFiles.Add( HelpFile ); - except on E: Exception do begin @@ -1398,6 +1411,7 @@ begin LoadingFilenameList.Free; Result := true; + UpdateEncodingComboBox; end; { Open the file or list of files in FileNames @@ -2377,8 +2391,16 @@ begin ImageIndices.Free; - //writeln(lText); - //writeln('-----------------------------'); + // apply encoding conversion + case Settings.Encoding of + encUTF8: lText := IPFToUTF8(lText); + encCP437: lText := CP437ToUTF8(lText); + encCP850: lText := CP850ToUTF8(lText); + encIBMGraph: lText := IBMGraphToUTF8(lText); + else + lText := IPFToUTF8(lText); + end; + { Load and insert annotations / notes } if not HelpFile.NotesLoaded then LoadNotesForFile(HelpFile); @@ -3153,6 +3175,23 @@ begin Style := bsLowered; end; + cbEncoding := TfpgComboBox.Create(ToolBar); + with cbEncoding do + begin + Name := 'cbEncoding'; + SetPosition(524, 2, 124, 22); + Anchors := [anRight,anTop]; + FontDesc := '#List'; + Hint := ''; + Items.Add('UTF-8'); + Items.Add('CP437'); + Items.Add('CP850'); + Items.Add('IBM Graph (cp437)'); + TabOrder := 10; + FocusItem := 0; + OnChange := @cbEncodingChanged; + end; + Bevel3 := TfpgBevel.Create(ToolBar); with Bevel3 do begin |