summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2013-04-25 16:28:44 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2013-04-25 16:28:44 +0100
commit26933c6be705219d5e9fabd33cb4d501f3651abd (patch)
tree4bfec2f85f21251fdd98df927703e11fdab1ee97
parentb0108d7f88a41ceadd707ed0b865da35956e2a50 (diff)
downloadfpGUI-26933c6be705219d5e9fabd33cb4d501f3651abd.tar.xz
docview: refactored text encoding version
docview now uses a single fpGUI call to do encoding conversions. This make is much easier to maintaing - a single method needs to be modified if new encoding conversions get added.
-rw-r--r--docview/components/richtext/CanvasFontManager.pas8
-rw-r--r--docview/src/HelpFile.pas35
-rw-r--r--docview/src/SettingsUnit.pas3
-rw-r--r--docview/src/frm_main.pas12
4 files changed, 13 insertions, 45 deletions
diff --git a/docview/components/richtext/CanvasFontManager.pas b/docview/components/richtext/CanvasFontManager.pas
index 9e9114ec..fe0123d3 100644
--- a/docview/components/richtext/CanvasFontManager.pas
+++ b/docview/components/richtext/CanvasFontManager.pas
@@ -313,14 +313,6 @@ var
t: TfpgString;
begin
t := s;
- //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/src/HelpFile.pas b/docview/src/HelpFile.pas
index ce3d9f8a..c013412c 100644
--- a/docview/src/HelpFile.pas
+++ b/docview/src/HelpFile.pas
@@ -9,6 +9,7 @@ interface
uses
Classes
,SysUtils
+ ,fpg_base
,fpg_imagelist
,IPFFileFormatUnit
,HelpTopic
@@ -18,9 +19,6 @@ uses
type
- TFontEncoding = (encUTF8, encCP437, encCP850, encIBMGraph);
-
-
TIndexEntry = class(TObject)
private
name: String;
@@ -173,7 +171,7 @@ type
procedure SetupFontSubstitutes( Substitutions: string );
public
NotesLoaded: boolean; // used externally
- Encoding: TFontEncoding;
+ Encoding: TfpgTextEncoding;
end;
// Returns helpfile that the given topic is within
@@ -396,14 +394,7 @@ begin
begin
lText := TTopic(TopicList[i]).Title;
// apply encoding conversion
- case Encoding of
- encUTF8: lText := IPFToUTF8(lText);
- encCP437: lText := CP437ToUTF8(lText);
- encCP850: lText := CP850ToUTF8(lText);
- encIBMGraph: lText := IBMGraphToUTF8(lText);
- else
- lText := IPFToUTF8(lText);
- end;
+ lText := ConvertTextToUTF8(Encoding, lText);
TTopic(TopicList[i]).Title := lText;
end;
except
@@ -663,7 +654,6 @@ var
pEnd: pByte;
pIndexData: pointer;
tmpIndexEntry: TIndexEntry;
- lText: string;
begin
LogEvent(LogParse, 'Read index');
_Index := TIndex.Create;
@@ -694,15 +684,7 @@ begin
if pEntryHeader^.TOCIndex < _Topics.Count then
begin
// apply encoding conversion
- case Encoding of
- encUTF8: lText := IPFToUTF8(EntryText);
- encCP437: lText := CP437ToUTF8(EntryText);
- encCP850: lText := CP850ToUTF8(EntryText);
- encIBMGraph: lText := IBMGraphToUTF8(EntryText);
- else
- lText := IPFToUTF8(EntryText);
- end;
- EntryText := lText;
+ EntryText := ConvertTextToUTF8(Encoding, EntryText);
tmpIndexEntry := TIndexEntry.Create(EntryText, TTopic(_Topics[pEntryHeader^.TOCIndex]), pEntryHeader^.flags);
_Index.Add(tmpIndexEntry);
end
@@ -1067,10 +1049,11 @@ 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;
+ case pFontSpec^.CodePage of
+ 437: Encoding := encCP437;
+ 850: Encoding := encCP850;
+ 866: Encoding := encCP866;
+ end;
end;
end;
diff --git a/docview/src/SettingsUnit.pas b/docview/src/SettingsUnit.pas
index 43083709..0825b10b 100644
--- a/docview/src/SettingsUnit.pas
+++ b/docview/src/SettingsUnit.pas
@@ -13,7 +13,6 @@ Uses
,fpg_base
,fpg_main
,CanvasFontManager
- ,HelpFile
;
Const
@@ -95,7 +94,7 @@ type
GlobalSearchLocation: TGlobalSearchLocation;
SearchDirectories: TStringList;
IPFTopicSaveAsEscaped: boolean;
- Encoding: TFontEncoding;
+ Encoding: TfpgTextEncoding;
end;
diff --git a/docview/src/frm_main.pas b/docview/src/frm_main.pas
index 97a9fd04..17507f51 100644
--- a/docview/src/frm_main.pas
+++ b/docview/src/frm_main.pas
@@ -1174,7 +1174,7 @@ end;
procedure TMainForm.cbEncodingChanged(Sender: TObject);
begin
- Settings.Encoding := TFontEncoding(cbEncoding.FocusItem);
+ Settings.Encoding := TfpgTextEncoding(cbEncoding.FocusItem);
DisplayTopic(CurrentTopic);
end;
@@ -2569,14 +2569,7 @@ begin
ImageIndices.Free;
// 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;
+ lText := ConvertTextToUTF8(HelpFile.Encoding, lText);
{ Load and insert annotations / notes }
if not HelpFile.NotesLoaded then
@@ -3467,6 +3460,7 @@ begin
Items.Add('UTF-8');
Items.Add('CP437');
Items.Add('CP850');
+ Items.Add('CP866');
Items.Add('IBM Graph (cp437)');
FocusItem := 0;
TabOrder := 10;