1 unit Unit1; 2 3 {$mode objfpc}{$H+} 4 5 interface 6 7 uses 8 Classes, SysUtils, Types, FileUtil, Forms, Controls, Graphics, Dialogs, 9 StdCtrls; 10 11 type 12 13 { TForm1 } 14 15 TForm1 = class(TForm) 16 procedure FormCreate(Sender: TObject); 17 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 18 procedure FormPaint(Sender: TObject); 19 private 20 21 public 22 mx,my: integer; 23 end; 24 25 var 26 Form1: TForm1; 27 28 implementation 29 30 {$R *.lfm} 31 32 uses BGRABitmap, BGRABitmapTypes, BGRAText, BGRAPath; 33 34 { TForm1 } 35 36 procedure TForm1.FormCreate(Sender: TObject); 37 begin 38 39 end; 40 41 procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, 42 Y: Integer); 43 begin 44 mx := x; 45 my := y; 46 Invalidate; 47 end; 48 49 procedure TForm1.FormPaint(Sender: TObject); 50 const zoom = 1; 51 TestText = 'في XHTML 1.0 يتم تحقيق ذلك بإضافة + العنصر المضمن bdo.';//'أب+'; 52 TestText2 = 'before مصر after سلام كَعْك.'; 53 var 54 image: TBGRABitmap; 55 TS, tempTS: TTextStyle; 56 y, prevHeight: Integer; 57 s: TSize; 58 p: TBGRAPath; 59 begin 60 image := TBGRABitmap.Create(ClientWidth div zoom, ClientHeight div zoom, BGRAWhite); 61 image.FontName := Font.Name; 62 image.FontHeight := round(Font.Height*96/PixelsPerInch); 63 image.FontQuality := fqSystemClearType; 64 65 Canvas.Brush.Style := bsClear; 66 67 fillchar(TS, sizeof(TS), 0); 68 TS.Opaque := False; 69 TS.Clipping:= true; 70 71 TS.RightToLeft := False; 72 TS.ShowPrefix := false; 73 ts.Alignment:= taRightJustify; 74 image.TextRect(Rect(5, 25, 240, 45), 5, 25, 'BGRA With RTL=False', TS, BGRA(0,0,0)); 75 ts.Alignment:= taLeftJustify; 76 image.TextRect(Rect(250, 25, image.Width, 45), 250, 25, TestText, TS, BGRA(0,0,0)); 77 78 TS.RightToLeft := True; 79 TS.ShowPrefix := true; 80 ts.Alignment:= taRightJustify; 81 image.TextRect(Rect(5, 95, 240, 135), 5, 95, 'BGRA' + LineEnding + 'With RTL=True', 82 TS, BGRA(0,0,0)); 83 ts.Alignment:= taLeftJustify; 84 image.TextRect(Rect(250, 95, image.Width, 135), 250, 95, TestText, TS, BGRA(0,0,0)); 85 86 image.TextOut(240,190, 'BGRA TextOut LTR', BGRABlack, taRightJustify); 87 image.TextOut(250,190, TestText, BGRABlack, false); 88 image.TextOut(240,210, 'BGRA TextOut RTL', BGRABlack, taRightJustify); 89 image.TextOut(250,210, TestText, BGRABlack, true); 90 91 image.TextOut(240,230, 'BGRA TextOut auto', BGRABlack, taRightJustify); 92 image.TextOut(250,230, TestText, BGRABlack); 93 image.TextOut(240,250, 'BGRA TextOut auto', BGRABlack, taRightJustify); 94 image.TextOut(250,250, TestText2, BGRABlack); 95 96 y := 280; 97 ts.Wordbreak := true; 98 ts.RightToLeft := false; 99 s := image.TextSize(TestText, image.Width-250, ts.RightToLeft); 100 image.TextOut(240,y, 'BGRA WordWrap LTR (fit ' + inttostr(image.TextFitInfo(TestText, image.Width-250)) + ')', BGRABlack, taRightJustify); 101 image.Rectangle(250, y, 250+s.cx,y+s.cy, BGRA(255,0,0,128), dmDrawWithTransparency); 102 image.TextRect(Rect(250, y, 250+s.cx,y+s.cy), 250,y, TestText, ts, BGRABlack); 103 inc(y, s.cy); 104 105 ts.RightToLeft := true; 106 s := image.TextSize(TestText, image.Width-250, ts.RightToLeft); 107 image.TextOut(240,y, 'BGRA WordWrap RTL', BGRABlack, taRightJustify); 108 image.Rectangle(250, y, 250+s.cx,y+s.cy, BGRA(255,0,0,128), dmDrawWithTransparency); 109 image.TextRect(Rect(250, y, 250+s.cx,y+s.cy), 250,y, TestText, ts, BGRABlack); 110 inc(y, s.cy); 111 ts.Wordbreak := false; 112 113 image.TextOut(240,y, 'BGRA TextOutAngle LTR', BGRABlack, taRightJustify); 114 image.FontStyle := [fsUnderline]; 115 image.TextOutAngle(250,y, -150, TestText2, BGRABlack, taLeftJustify, False); 116 image.FontStyle := []; 117 inc(y,20); 118 119 image.TextOut(240,y, 'BGRA TextOutAngle RTL', BGRABlack, taRightJustify); 120 image.FontStyle := [fsUnderline]; 121 image.TextOutAngle(250,y, -150, TestText2, BGRABlack, taLeftJustify, True); 122 image.FontStyle := []; 123 inc(y,20); 124 125 image.TextOut(240,y, 'BGRA TextOutAngle auto', BGRABlack, taRightJustify); 126 image.FontStyle := [fsUnderline]; 127 image.TextOutAngle(250,y, -150, TestText2, BGRABlack, taLeftJustify); 128 image.FontStyle := []; 129 inc(y,40); 130 131 image.FontHeight := 25; 132 image.TextOut(240,y, 'Curved LTR', BGRABlack, taRightJustify); 133 p := TBGRAPath.Create; 134 p.translate(image.FontFullHeight/2, image.FontFullHeight/2); 135 p.moveTo(250,y); 136 p.arc(500,y, 250,50, 0, Pi,0, true); 137 image.FontVerticalAnchor:= fvaCapCenter; 138 image.FontBidiMode:= fbmLeftToRight; 139 image.TextOutCurved(p, TestText2, BGRABlack, taLeftJustify, 0); 140 image.FontVerticalAnchor:= fvaTop; 141 p.Free; 142 inc(y,round(image.FontFullHeight*1.2)); 143 144 image.TextOut(240,y, 'Curved RTL', BGRABlack, taRightJustify); 145 p := TBGRAPath.Create; 146 p.translate(image.FontFullHeight/2, image.FontFullHeight/2); 147 p.moveTo(250,y); 148 p.arc(500,y, 250,50, 0, Pi,0, true); 149 image.FontVerticalAnchor:= fvaCapCenter; 150 image.FontBidiMode:= fbmRightToLeft; 151 image.TextOutCurved(p, TestText2, BGRABlack, taLeftJustify, 0); 152 image.FontVerticalAnchor:= fvaTop; 153 p.Free; 154 inc(y,round(image.FontFullHeight*1.2)); 155 156 image.TextOut(240,y, 'Curved auto', BGRABlack, taRightJustify); 157 p := TBGRAPath.Create; 158 p.translate(image.FontFullHeight/2, image.FontFullHeight/2); 159 p.moveTo(250,y); 160 p.arc(500,y, 250,50, 0, Pi,0, true); 161 image.FontVerticalAnchor:= fvaCapCenter; 162 image.FontBidiMode:= fbmAuto; 163 image.TextOutCurved(p, TestText2, BGRABlack, taLeftJustify, 0); 164 image.FontVerticalAnchor:= fvaTop; 165 p.Free; 166 inc(y,round(image.FontFullHeight*1.2)); 167 168 169 image.FontFullHeight := 40; 170 ts.Alignment := taLeftJustify; 171 TS.EndEllipsis := true; 172 TS.RightToLeft := false; 173 TS.Wordbreak := false; 174 image.TextRect(rect(0,0,ClientWidth,ClientHeight), mx,my-50, 'BGRA test ellipsis', ts, CSSGray); 175 TS.EndEllipsis:= false; 176 177 image.Draw(Canvas, 0,0, true); 178 179 image.Free; 180 181 Canvas.Font.Height := round(Font.Height*96/PixelsPerInch); 182 Canvas.Font.Color := clBlack; 183 TS.RightToLeft := False; 184 TS.ShowPrefix := false; 185 ts.Alignment:= taRightJustify; 186 Canvas.TextRect(Rect(5, 5, 240, 25), 5, 5, 'TCanvas With RTL=False', TS); 187 ts.Alignment:= taLeftJustify; 188 Canvas.TextRect(Rect(250, 5, Canvas.Width, 25), 250, 5, TestText, TS); 189 190 TS.RightToLeft := True; 191 TS.ShowPrefix := true; 192 ts.Alignment:= taRightJustify; 193 Canvas.TextRect(Rect(5, 55, 240, 95), 5, 55, 'TCanvas'+LineEnding+'With &RTL=True', TS); 194 ts.Alignment:= taLeftJustify; 195 Canvas.TextRect(Rect(250, 55, Canvas.Width, 95), 250, 55, TestText, TS); 196 197 ts.Alignment:= taRightJustify; 198 Canvas.TextRect(Rect(5, 140, 240, 160), 5, 140, 'TCanvas TextOut LTR', TS); 199 Canvas.TextOut(250,140, TestText); 200 tempTS := Canvas.TextStyle; 201 tempTS.RightToLeft := true; 202 Canvas.TextStyle := tempTS; 203 Canvas.TextRect(Rect(5, 160, 240, 180), 5, 160, 'TCanvas TextOut RTL', TS); 204 Canvas.TextOut(250,160, TestText); 205 tempTS := Canvas.TextStyle; 206 tempTS.RightToLeft := false; 207 Canvas.TextStyle := tempTS; 208 209 prevHeight := Canvas.Font.Height; 210 Canvas.Font.Color := clGray; 211 Canvas.Font.Height := FontFullHeightSign * 40; 212 ts.Alignment := taLeftJustify; 213 TS.EndEllipsis := true; 214 TS.RightToLeft := false; 215 TS.Wordbreak := false; 216 Canvas.TextRect(rect(0,0,ClientWidth,ClientHeight), mx,my, 'TCanvas test ellipsis', ts); 217 TS.EndEllipsis:= false; 218 Canvas.Font.Height := prevHeight; 219 end; 220 221 end. 222 223