From d1956180b1822175868600fc3c7c922f51ab31db Mon Sep 17 00:00:00 2001 From: skalogryz Date: Mon, 13 Jan 2020 15:39:38 +0000 Subject: [PATCH] richmemo: adding support for super and sub script into manually loading RTF. patch by Vladimir Rybant. (source: https://github.com/vrybant/unboundbible/commit/783938acdd4d89a66d93ff31dae511ad1f6cbf4f) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7283 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/richmemo/richmemortf.pas | 21 +++++++++++++++++++++ components/richmemo/rtfdata.inc | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/components/richmemo/richmemortf.pas b/components/richmemo/richmemortf.pas index c04b21578..f36848aa5 100644 --- a/components/richmemo/richmemortf.pas +++ b/components/richmemo/richmemortf.pas @@ -451,6 +451,11 @@ begin rtfFontSize: prm.fnt.Size:=round(aparam/2); rtfUnderline: if aparam=0 then Exclude(prm.fnt.Style,fsUnderline) else Include(prm.fnt.Style, fsUnderline); rtfNoUnderline: Exclude(prm.fnt.Style, fsUnderline); + + rtfSuperScript: prm.fnt.VScriptPos:=vpSuperscript; + rtfSubScript : prm.fnt.VScriptPos:=vpSubScript; + rtfNoSuperSub : prm.fnt.VScriptPos:=vpNormal; + rtfHighlight: begin prm.fnt.HasBkClr := (aparam>0) and (aparam<=high(HColor)); if prm.fnt.HasBkClr then begin @@ -720,6 +725,7 @@ var isbold : Boolean; isitalic : Boolean; isuline : Boolean; + issupersub: Boolean; isColor : integer; pm : TParaMetric; @@ -796,6 +802,7 @@ begin rng:=root; isbold:=false; isitalic:=false; + issupersub:=false; iscolor:=0; while Assigned(rng) do begin u:=ARich.GetUText(rng.textStart, rng.textLength); @@ -826,6 +833,20 @@ begin if isitalic then RtfOut('\i0'); isitalic:=false; end; + + if rng.font.VScriptPos=vpSuperScript then begin + RtfOut('\super'); + issupersub:=true; + end; + if rng.font.VScriptPos=vpSubScript then begin + RtfOut('\sub'); + issupersub:=true; + end; + if rng.font.VScriptPos=vpNormal then begin + if issupersub then RtfOut('\nosupersub'); + issupersub:=false; + end; + RtfOut(' '); i:=1; diff --git a/components/richmemo/rtfdata.inc b/components/richmemo/rtfdata.inc index f3b8e91f0..73c800833 100644 --- a/components/richmemo/rtfdata.inc +++ b/components/richmemo/rtfdata.inc @@ -335,6 +335,7 @@ const rtfBackColor = 21; rtfGray = 22; rtfHighlight = 23; + rtfNoSuperSub = 24; rtfPictAttr = 13; rtfMacQD = 0; @@ -469,7 +470,7 @@ type ---------------------------------------------------------------------} const - rtfKey : Array [0..284] of TRTFKey = + rtfKey : Array [0..287] of TRTFKey = ( ( rtfKMajor: RTFSPECIALCHAR; rtfKMinor : rtfCURHEADPICT; rtfKStr : 'chpict'; rtfKhash : 0), ( rtfKMajor: rtfSpecialChar; rtfKMinor: rtfCurHeadDate; rtfKstr : 'chdate'; rtfkHash : 0), @@ -529,6 +530,9 @@ const ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfNoUnderline; rtfKstr : 'ulnone'; rtfkHash : 0), ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfSuperScript; rtfKstr : 'up'; rtfkHash : 0), ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfSubScript; rtfKstr : 'dn'; rtfkHash : 0), + ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfSuperScript; rtfKstr : 'super'; rtfkHash : 0), + ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfSubScript; rtfKstr : 'sub'; rtfkHash : 0), + ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfNoSuperSub; rtfKstr : 'nosupersub'; rtfkHash : 0), ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfRevised; rtfKstr : 'revised'; rtfkHash : 0), ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfForeColor; rtfKstr : 'cf'; rtfkHash : 0), ( rtfKMajor: rtfCharAttr; rtfKMinor: rtfBackColor; rtfKstr : 'cb'; rtfkHash : 0),