source: trunk/Packages/bgrabitmap/bgrafontgl.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 19.5 KB
Line 
1unit BGRAFontGL;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, BGRAGraphics, BGRAOpenGLType, BGRABitmapTypes,
9 AvgLvlTree;
10
11type
12 { TRenderedGlyph }
13
14 TRenderedGlyph = class
15 private
16 FIdentifier: UTF8String;
17 FTexture: IBGLTexture;
18 FHorizontalOverflowPx, FVerticalOverflowPx, FAdvancePx: integer;
19 public
20 constructor Create(AIdentifier: UTF8String; ATexture: IBGLTexture;
21 AHorizontalOverflowPx, AVerticalOverflowPx: integer);
22 procedure Draw(x,y,Scale: single; AColor: TBGRAPixel); overload;
23 procedure Draw(x,y,Scale: single; AGradTopLeft, AGradTopRight, AGradBottomRight, AGradBottomLeft: TBGRAPixel); overload;
24 property Identifier: UTF8String read FIdentifier;
25 property AdvancePx: integer read FAdvancePx;
26 end;
27
28 { IBGLRenderedFont }
29
30 IBGLRenderedFont = interface(IBGLFont)
31 function GetBackgroundColor: TBGRAPixel;
32 function GetColor: TBGRAPixel;
33 function GetFontEmHeight: integer;
34 function GetFontFullHeight: integer;
35 function GetHorizontalOverflow: single;
36 function GetName: string;
37 function GetQuality: TBGRAFontQuality;
38 function GetStyle: TFontStyles;
39 function GetVerticalOverflow: single;
40 procedure SetBackgroundColor(AValue: TBGRAPixel);
41 procedure SetColor(AValue: TBGRAPixel);
42 procedure SetFontEmHeight(AValue: integer);
43 procedure SetFontFullHeight(AValue: integer);
44 procedure SetHorizontalOverflow(AValue: single);
45 procedure SetName(AValue: string);
46 procedure SetQuality(AValue: TBGRAFontQuality);
47 procedure SetStyle(AValue: TFontStyles);
48 procedure SetVerticalOverflow(AValue: single);
49
50 property Name: string read GetName write SetName;
51 property Style: TFontStyles read GetStyle write SetStyle;
52 property Quality: TBGRAFontQuality read GetQuality write SetQuality;
53 property EmHeight: integer read GetFontEmHeight write SetFontEmHeight;
54 property FullHeight: integer read GetFontFullHeight write SetFontFullHeight;
55 property Color: TBGRAPixel read GetColor write SetColor;
56 property HorizontalOverflow: single read GetHorizontalOverflow write SetHorizontalOverflow;
57 property VerticalOverflow: single read GetVerticalOverflow write SetVerticalOverflow;
58 property BackgroundColor: TBGRAPixel read GetBackgroundColor write SetBackgroundColor;
59 end;
60
61 { TBGLRenderedFont }
62
63 TBGLRenderedFont = class(TBGLCustomFont,IBGLRenderedFont)
64 private
65 FGlyphs: TAvgLvlTree;
66
67 FName: string;
68 FColor: TBGRAPixel;
69 FBackgroundColor: TBGRAPixel;
70 FEmHeight: integer;
71 FHorizontalOverflow: single;
72 FVerticalOverflow: single;
73 FQuality: TBGRAFontQuality;
74 FStyle: TFontStyles;
75 FGradTopLeft, FGradTopRight, FGradBottomRight, FGradBottomLeft: TBGRAPixel;
76 FUseGradientColor: boolean;
77 FClipped: boolean;
78 FWordBreakHandler: TWordBreakHandler;
79
80 function CompareGlyph({%H-}Tree: TAvgLvlTree; Data1, Data2: Pointer): integer;
81 function FindGlyph(AIdentifier: string): TAvgLvlTreeNode;
82 function GetBackgroundColor: TBGRAPixel;
83 function GetColor: TBGRAPixel;
84 function GetFontEmHeight: integer;
85 function GetGlyph(AIdentifier: string): TRenderedGlyph;
86 function GetHorizontalOverflow: single;
87 function GetName: string;
88 function GetQuality: TBGRAFontQuality;
89 function GetStyle: TFontStyles;
90 function GetVerticalOverflow: single;
91 procedure SetGlyph(AIdentifier: string; AValue: TRenderedGlyph);
92 function GetFontFullHeight: integer;
93 procedure SetBackgroundColor(AValue: TBGRAPixel);
94 procedure SetColor(AValue: TBGRAPixel);
95 procedure SetFontEmHeight(AValue: integer);
96 procedure SetFontFullHeight(AValue: integer);
97 procedure SetHorizontalOverflow(AValue: single);
98 procedure SetName(AValue: string);
99 procedure SetQuality(AValue: TBGRAFontQuality);
100 procedure SetStyle(AValue: TFontStyles);
101 procedure SetVerticalOverflow(AValue: single);
102 protected
103 FRenderer: TBGRACustomFontRenderer;
104 FRendererOwned: boolean;
105 function LoadFromFile({%H-}AFilename: UTF8String): boolean; override;
106 procedure FreeMemoryOnDestroy; override;
107 function CreateGlyph(AIdentifier: string): TRenderedGlyph; virtual;
108 procedure CopyFontToRenderer; virtual;
109 procedure DoTextOut(X, Y: Single; const Text : UTF8String; AColor: TBGRAPixel; AHorizontalAlign: TAlignment; AVerticalAlign: TTextLayout); overload; virtual;
110 procedure DoTextOut(X, Y: Single; const Text : UTF8String; AColor: TBGRAPixel); overload; override;
111 procedure DoTextRect(X, Y, Width, Height: Single; const Text : UTF8String; AColor: TBGRAPixel); override;
112 function GetClipped: boolean; override;
113 function GetUseGradientColors: boolean; override;
114 procedure SetClipped(AValue: boolean); override;
115 procedure SetUseGradientColors(AValue: boolean); override;
116 procedure DiscardGlyphs; virtual;
117 procedure DefaultWordBreakHandler(var ABefore, AAfter: string);
118 procedure SplitText(var ATextUTF8: string; AMaxWidth: single; out ARemainsUTF8: string);
119 function GetWrappedLines(ATextUTF8: string; AWidth: single): TStringList;
120 public
121 constructor Create(ARenderer: TBGRACustomFontRenderer; ARendererOwned: boolean = true);
122 procedure FreeMemory; override;
123 function TextWidth(const Text: UTF8String): single; override;
124 function TextHeight(const {%H-}Text: UTF8String): single; override;
125 function TextHeight(const Text: UTF8String; AWidth: single): single; override;
126 procedure SetGradientColors(ATopLeft, ATopRight, ABottomRight, ABottomLeft: TBGRAPixel); override;
127 property Name: string read GetName write SetName;
128 property Style: TFontStyles read GetStyle write SetStyle;
129 property Quality: TBGRAFontQuality read GetQuality write SetQuality;
130 property EmHeight: integer read GetFontEmHeight write SetFontEmHeight;
131 property FullHeight: integer read GetFontFullHeight write SetFontFullHeight;
132 property Color: TBGRAPixel read GetColor write SetColor;
133 property HorizontalOverflow: single read GetHorizontalOverflow write SetHorizontalOverflow;
134 property VerticalOverflow: single read GetVerticalOverflow write SetVerticalOverflow;
135 property BackgroundColor: TBGRAPixel read GetBackgroundColor write SetBackgroundColor;
136 property WordBreakHandler: TWordBreakHandler read FWordBreakHandler write FWordBreakHandler;
137 property Glyph[AIdentifier: string]: TRenderedGlyph read GetGlyph;
138 end;
139
140implementation
141
142uses BGRAUTF8;
143
144{ TRenderedGlyph }
145
146constructor TRenderedGlyph.Create(AIdentifier: UTF8String; ATexture: IBGLTexture;
147 AHorizontalOverflowPx, AVerticalOverflowPx: integer);
148begin
149 FIdentifier := AIdentifier;
150 FTexture := ATexture;
151 FHorizontalOverflowPx:= AHorizontalOverflowPx;
152 FVerticalOverflowPx:= AVerticalOverflowPx;
153 FAdvancePx := ATexture.Width - 2*FHorizontalOverflowPx;
154end;
155
156procedure TRenderedGlyph.Draw(x, y, Scale: single; AColor: TBGRAPixel);
157begin
158 FTexture.StretchDraw(x-FHorizontalOverflowPx*Scale,y-FVerticalOverflowPx*Scale, FTexture.Width*Scale, FTexture.Height*Scale, AColor);
159end;
160
161procedure TRenderedGlyph.Draw(x, y, Scale: single; AGradTopLeft, AGradTopRight,
162 AGradBottomRight, AGradBottomLeft: TBGRAPixel);
163begin
164 FTexture.SetGradientColors(AGradTopLeft,AGradTopRight, AGradBottomRight,AGradBottomLeft);
165 FTexture.StretchDraw(x-FHorizontalOverflowPx*Scale,y-FVerticalOverflowPx*Scale, FTexture.Width*Scale, FTexture.Height*Scale);
166 FTexture.GradientColors := false;
167end;
168
169{ TBGLRenderedFont }
170
171function TBGLRenderedFont.CompareGlyph(Tree: TAvgLvlTree; Data1, Data2: Pointer): integer;
172begin
173 result := CompareStr(TRenderedGlyph(Data1).Identifier,TRenderedGlyph(Data2).Identifier);
174end;
175
176function TBGLRenderedFont.FindGlyph(AIdentifier: string): TAvgLvlTreeNode;
177var Comp: integer;
178 Node: TAvgLvlTreeNode;
179begin
180 Node:=FGlyphs.Root;
181 while (Node<>nil) do begin
182 Comp:=CompareStr(AIdentifier,TRenderedGlyph(Node.Data).Identifier);
183 if Comp=0 then break;
184 if Comp<0 then begin
185 Node:=Node.Left
186 end else begin
187 Node:=Node.Right
188 end;
189 end;
190 result := Node;
191end;
192
193function TBGLRenderedFont.GetBackgroundColor: TBGRAPixel;
194begin
195 result := FBackgroundColor;
196end;
197
198function TBGLRenderedFont.GetColor: TBGRAPixel;
199begin
200 result := FColor;
201end;
202
203function TBGLRenderedFont.GetFontEmHeight: integer;
204begin
205 result := FEmHeight;
206end;
207
208function TBGLRenderedFont.CreateGlyph(AIdentifier: string): TRenderedGlyph;
209var b: TBGLCustomBitmap;
210 hOverflow, vOverflow: integer;
211begin
212 CopyFontToRenderer;
213 with FRenderer.TextSize(AIdentifier) do
214 begin
215 hOverflow := round(cx*HorizontalOverflow)+1;
216 vOverflow:= round(cy*VerticalOverflow)+1;
217 b:= BGLBitmapFactory.Create(cx+2*hOverflow,cy+2*vOverflow,BackgroundColor);
218 FRenderer.TextOut(b, hOverflow,vOverflow, AIdentifier, Color, taLeftJustify);
219 result:= TRenderedGlyph.Create(AIdentifier,b.MakeTextureAndFree,hOverflow,vOverflow);
220 end;
221end;
222
223procedure TBGLRenderedFont.CopyFontToRenderer;
224begin
225 FRenderer.FontName := FName;
226 FRenderer.FontEmHeight := FEmHeight;
227 FRenderer.FontOrientation := 0;
228 FRenderer.FontQuality := FQuality;
229 FRenderer.FontStyle := FStyle;
230end;
231
232procedure TBGLRenderedFont.DoTextOut(X, Y: Single; const Text: UTF8String;
233 AColor: TBGRAPixel; AHorizontalAlign: TAlignment; AVerticalAlign: TTextLayout);
234var
235 pstr: pchar;
236 left,charlen: integer;
237 nextchar: string;
238 g: TRenderedGlyph;
239begin
240 if Text = '' then exit;
241
242 pstr := @Text[1];
243 left := length(Text);
244 case AHorizontalAlign of
245 taCenter: x -= round(TextWidth(Text)/2);
246 taRightJustify: x -= TextWidth(Text);
247 end;
248 case AVerticalAlign of
249 tlCenter: y -= round(TextHeight(Text)/2);
250 tlBottom: y -= TextHeight(Text)*Scale;
251 end;
252 while left > 0 do
253 begin
254 charlen := UTF8CharacterLength(pstr);
255 setlength(nextchar, charlen);
256 move(pstr^, nextchar[1], charlen);
257 inc(pstr,charlen);
258 dec(left,charlen);
259
260 g := GetGlyph(nextchar);
261 if g <> nil then
262 begin
263 if FUseGradientColor then
264 g.Draw(x,y,Scale,FGradTopLeft,FGradTopRight,FGradBottomRight,FGradBottomLeft)
265 else
266 g.Draw(x,y,Scale,AColor);
267 x += (g.AdvancePx + StepX) * Scale;
268 end;
269 end;
270end;
271
272procedure TBGLRenderedFont.DoTextOut(X, Y: Single; const Text: UTF8String;
273 AColor: TBGRAPixel);
274begin
275 if Justify then
276 DoTextOut(X,Y,Text,AColor,taLeftJustify,VerticalAlign)
277 else
278 DoTextOut(X,Y,Text,AColor,HorizontalAlign,VerticalAlign);
279end;
280
281procedure TBGLRenderedFont.DoTextRect(X, Y, Width, Height: Single;
282 const Text: UTF8String; AColor: TBGRAPixel);
283
284 procedure DoDrawTextLine(LineY, LineWidth: Single; ALine: string; AJustify: boolean);
285 var CurX: single;
286 words: TStringList;
287 wordStart: integer;
288 i: Integer;
289 begin
290 if AJustify then
291 begin
292 words := TStringList.Create;
293 wordStart := 1;
294 for i := 1 to length(ALine) do
295 begin
296 if ALine[i]=' ' then
297 begin
298 words.Add(copy(ALine,wordStart,i-wordStart));
299 wordStart := i+1;
300 end;
301 end;
302 words.add(copy(ALine,wordStart,length(ALine)+1-wordStart));
303 CurX := X;
304 LineWidth := 0;
305 for i := 0 to words.Count-1 do
306 LineWidth += TextWidth(words[i]);
307
308 for i := 0 to words.Count-1 do
309 begin
310 DoTextOut(CurX+round((Width-LineWidth)/(words.Count-1)*i),LineY,words[i],AColor,taLeftJustify,tlTop);
311 CurX += TextWidth(words[i]);
312 end;
313 words.Free;
314 end else
315 begin
316 Case HorizontalAlign of
317 taCenter: CurX := round(X+(Width-LineWidth)/2);
318 taRightJustify: CurX := X+Width-LineWidth;
319 else
320 CurX := X;
321 end;
322 DoTextOut(CurX,LineY,ALine,AColor,taLeftJustify,tlTop);
323 end;
324 end;
325
326var CurY: Single;
327 lineHeight: Single;
328 lines: TStringList;
329 i,originalNbLines: Integer;
330 maxLineCount: int64;
331begin
332 If Text='' then exit;
333 lines := GetWrappedLines(Text,Width);
334 lineHeight := FullHeight * Scale;
335 originalNbLines := lines.Count;
336
337 if Clipped then
338 begin
339 if lineHeight = 0 then exit;
340 maxLineCount := trunc(Height/lineHeight);
341 if maxLineCount <= 0 then exit;
342 while lines.Count > maxLineCount do
343 lines.Delete(lines.Count-1);
344 end;
345
346 case VerticalAlign of
347 tlCenter: CurY := round(Y+( Height - lines.Count*lineHeight )/2);
348 tlBottom: CurY := Y + Height - lines.Count*lineHeight;
349 else CurY := Y;
350 end;
351
352 for i := 0 to lines.Count-1 do
353 begin
354 DoDrawTextLine(CurY,TextWidth(lines[i]),lines[i],Justify and (i<>originalNbLines-1));
355 CurY += lineHeight;
356 end;
357 lines.Free;
358end;
359
360function TBGLRenderedFont.GetGlyph(AIdentifier: string): TRenderedGlyph;
361var Node: TAvgLvlTreeNode;
362begin
363 Node := FindGlyph(AIdentifier);
364 if Node = nil then
365 begin
366 if UTF8Length(AIdentifier)<>1 then
367 result := nil
368 else
369 begin
370 result := CreateGlyph(AIdentifier);
371 SetGlyph(AIdentifier, result);
372 end;
373 end
374 else
375 result := TRenderedGlyph(Node.Data);
376end;
377
378function TBGLRenderedFont.GetHorizontalOverflow: single;
379begin
380 result := FHorizontalOverflow;
381end;
382
383function TBGLRenderedFont.GetName: string;
384begin
385 result := FName;
386end;
387
388function TBGLRenderedFont.GetQuality: TBGRAFontQuality;
389begin
390 result := FQuality;
391end;
392
393function TBGLRenderedFont.GetStyle: TFontStyles;
394begin
395 result := FStyle;
396end;
397
398function TBGLRenderedFont.GetVerticalOverflow: single;
399begin
400 result := FVerticalOverflow;
401end;
402
403procedure TBGLRenderedFont.SetGlyph(AIdentifier: string; AValue: TRenderedGlyph);
404var Node: TAvgLvlTreeNode;
405begin
406 if AValue.Identifier <> AIdentifier then
407 raise exception.Create('Identifier mismatch');
408 Node := FindGlyph(AIdentifier);
409 if Node <> nil then
410 begin
411 if pointer(AValue) <> Node.Data then
412 TRenderedGlyph(Node.Data).Free;
413 Node.Data := AValue;
414 end else
415 FGlyphs.Add(pointer(AValue));
416end;
417
418procedure TBGLRenderedFont.SetStyle(AValue: TFontStyles);
419begin
420 if FStyle=AValue then Exit;
421 FStyle:=AValue;
422 DiscardGlyphs;
423end;
424
425procedure TBGLRenderedFont.SetVerticalOverflow(AValue: single);
426begin
427 if FVerticalOverflow=AValue then Exit;
428 FVerticalOverflow:=AValue;
429 DiscardGlyphs;
430end;
431
432function TBGLRenderedFont.GetClipped: boolean;
433begin
434 result := FClipped;
435end;
436
437function TBGLRenderedFont.GetUseGradientColors: boolean;
438begin
439 result := FUseGradientColor;
440end;
441
442procedure TBGLRenderedFont.SetClipped(AValue: boolean);
443begin
444 FClipped:= AValue;
445end;
446
447procedure TBGLRenderedFont.SetUseGradientColors(AValue: boolean);
448begin
449 FUseGradientColor:= AValue;
450end;
451
452procedure TBGLRenderedFont.DiscardGlyphs;
453begin
454 FGlyphs.FreeAndClear;
455end;
456
457procedure TBGLRenderedFont.DefaultWordBreakHandler(var ABefore, AAfter: string);
458begin
459 BGRADefaultWordBreakHandler(ABefore,AAfter);
460end;
461
462function TBGLRenderedFont.GetWrappedLines(ATextUTF8: string; AWidth: single
463 ): TStringList;
464var
465 ARemains: string;
466begin
467 result := TStringList.Create;
468 repeat
469 SplitText(ATextUTF8, AWidth, ARemains);
470 result.Add(ATextUTF8);
471 ATextUTF8 := ARemains;
472 until ARemains = '';
473end;
474
475procedure TBGLRenderedFont.SplitText(var ATextUTF8: string; AMaxWidth: single;
476 out ARemainsUTF8: string);
477var
478 pstr: pchar;
479 p,left,charlen: integer;
480 totalWidth: single;
481 firstChar: boolean;
482 nextchar: string;
483 g: TRenderedGlyph;
484begin
485 totalWidth := 0;
486 if ATextUTF8 = '' then
487 begin
488 ARemainsUTF8 := '';
489 exit;
490 end else
491 begin
492 p := 1;
493 pstr := @ATextUTF8[1];
494 left := length(ATextUTF8);
495 firstChar := true;
496 while left > 0 do
497 begin
498 if RemoveLineEnding(ATextUTF8,p) then
499 begin
500 ARemainsUTF8 := copy(ATextUTF8,p,length(ATextUTF8)-p+1);
501 ATextUTF8 := copy(ATextUTF8,1,p-1);
502 exit;
503 end;
504
505 charlen := UTF8CharacterLength(pstr);
506 setlength(nextchar, charlen);
507 move(pstr^, nextchar[1], charlen);
508 inc(pstr,charlen);
509
510 g := GetGlyph(nextchar);
511 if g <> nil then
512 begin
513 if not firstChar then totalWidth += StepX*Scale;
514 totalWidth += g.AdvancePx*Scale;
515 if not firstChar and (totalWidth > AMaxWidth) then
516 begin
517 ARemainsUTF8:= copy(ATextUTF8,p,length(ATextUTF8)-p+1);
518 ATextUTF8 := copy(ATextUTF8,1,p-1);
519 if Assigned(FWordBreakHandler) then
520 FWordBreakHandler(ATextUTF8,ARemainsUTF8) else
521 DefaultWordBreakHandler(ATextUTF8,ARemainsUTF8);
522 exit;
523 end;
524 end;
525
526 dec(left,charlen);
527 inc(p,charlen);
528 firstChar := false;
529 end;
530 end;
531 ARemainsUTF8 := ''; //no split
532end;
533
534procedure TBGLRenderedFont.SetName(AValue: string);
535begin
536 if FName=AValue then Exit;
537 FName:=AValue;
538 DiscardGlyphs;
539end;
540
541procedure TBGLRenderedFont.SetFontEmHeight(AValue: integer);
542begin
543 if FEmHeight=AValue then Exit;
544 FEmHeight:=AValue;
545 DiscardGlyphs;
546end;
547
548function TBGLRenderedFont.GetFontFullHeight: integer;
549begin
550 if FEmHeight < 0 then
551 result := -EmHeight
552 else
553 result := FRenderer.TextSize('Hg').cy;
554end;
555
556procedure TBGLRenderedFont.SetBackgroundColor(AValue: TBGRAPixel);
557begin
558 if FBackgroundColor=AValue then Exit;
559 FBackgroundColor:=AValue;
560 DiscardGlyphs;
561end;
562
563procedure TBGLRenderedFont.SetColor(AValue: TBGRAPixel);
564begin
565 if FColor=AValue then Exit;
566 FColor:=AValue;
567 DiscardGlyphs;
568end;
569
570procedure TBGLRenderedFont.SetFontFullHeight(AValue: integer);
571begin
572 EmHeight:= -AValue;
573end;
574
575procedure TBGLRenderedFont.SetHorizontalOverflow(AValue: single);
576begin
577 if FHorizontalOverflow=AValue then Exit;
578 FHorizontalOverflow:=AValue;
579 DiscardGlyphs;
580end;
581
582procedure TBGLRenderedFont.SetQuality(AValue: TBGRAFontQuality);
583begin
584 if FQuality=AValue then Exit;
585 FQuality:=AValue;
586 DiscardGlyphs;
587end;
588
589function TBGLRenderedFont.LoadFromFile(AFilename: UTF8String): boolean;
590begin
591 result := false;
592end;
593
594procedure TBGLRenderedFont.FreeMemoryOnDestroy;
595begin
596 FreeMemory;
597 if FRendererOwned then FreeAndNil(FRenderer);
598 FreeAndNil(FGlyphs);
599end;
600
601constructor TBGLRenderedFont.Create(ARenderer: TBGRACustomFontRenderer;
602 ARendererOwned: boolean);
603begin
604 Init;
605 FRenderer := ARenderer;
606 FRendererOwned := ARendererOwned;
607
608 FName := 'Arial';
609 FColor := BGRAWhite;
610 FBackgroundColor := BGRAPixelTransparent;
611 FEmHeight := 20;
612 FStyle := [];
613 FHorizontalOverflow := 0.33;
614 FVerticalOverflow := 0;
615 FQuality := fqFineAntialiasing;
616
617 FGradTopLeft := BGRAWhite;
618 FGradTopRight := BGRAWhite;
619 FGradBottomLeft := BGRAWhite;
620 FGradBottomRight := BGRAWhite;
621 FUseGradientColor:= false;
622 FClipped:= false;
623
624 FGlyphs := TAvgLvlTree.CreateObjectCompare(@CompareGlyph);
625 FWordBreakHandler:= nil;
626end;
627
628procedure TBGLRenderedFont.FreeMemory;
629begin
630 DiscardGlyphs;
631 inherited FreeMemory;
632end;
633
634function TBGLRenderedFont.TextWidth(const Text: UTF8String): single;
635var
636 pstr: pchar;
637 left,charlen: integer;
638 nextchar: string;
639 g: TRenderedGlyph;
640 firstChar: boolean;
641begin
642 result := 0;
643 if Text = '' then exit;
644
645 firstChar := true;
646 pstr := @Text[1];
647 left := length(Text);
648 while left > 0 do
649 begin
650 charlen := UTF8CharacterLength(pstr);
651 setlength(nextchar, charlen);
652 move(pstr^, nextchar[1], charlen);
653 inc(pstr,charlen);
654 dec(left,charlen);
655
656 g := GetGlyph(nextchar);
657 if g <> nil then
658 begin
659 if firstChar then
660 firstchar := false
661 else
662 result += StepX * Scale;
663 result += g.AdvancePx * Scale;
664 end;
665 end;
666end;
667
668function TBGLRenderedFont.TextHeight(const Text: UTF8String): single;
669begin
670 result := FullHeight * Scale;
671end;
672
673function TBGLRenderedFont.TextHeight(const Text: UTF8String; AWidth: single
674 ): single;
675var
676 lines: TStringList;
677begin
678 lines := GetWrappedLines(Text, AWidth);
679 result := lines.Count * (FullHeight * Scale);
680 lines.Free;
681end;
682
683procedure TBGLRenderedFont.SetGradientColors(ATopLeft, ATopRight, ABottomRight,
684 ABottomLeft: TBGRAPixel);
685begin
686 FGradTopLeft := ATopLeft;
687 FGradTopRight := ATopRight;
688 FGradBottomLeft := ABottomLeft;
689 FGradBottomRight := ABottomRight;
690 GradientColors := true;
691end;
692
693end.
694
Note: See TracBrowser for help on using the repository browser.