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/src | |
parent | 1e649f145f5a0930755b24756081f7399ab2847f (diff) | |
download | fpGUI-fa8acc2b58592ea1382ae8a986c3c159e53229ce.tar.xz |
temp storage for Encoding implementation in DocView
Diffstat (limited to 'docview/src')
-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 |
3 files changed, 56 insertions, 10 deletions
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 |