Changeset 494 for GraphicTest/Packages/bgrabitmap/bgratext.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgratext.pas
r472 r494 4 4 5 5 interface 6 7 {$IFDEF LINUX} 8 {$DEFINE LCL_RENDERER_IS_FINE} 9 {$DEFINE LCL_CLEARTYPE_RENDERER_IS_FINE} 10 {$ENDIF} 11 {$IFDEF FREEBSD} 12 {$DEFINE LCL_RENDERER_IS_FINE} 13 {$DEFINE LCL_CLEARTYPE_RENDERER_IS_FINE} 14 {$ENDIF} 15 {$IFDEF DARWIN} 16 {$DEFINE LCL_RENDERER_IS_FINE} 17 {$DEFINE RENDER_TEXT_ON_TBITMAP} 18 {$ENDIF} 6 19 7 20 { 8 21 Font rendering units : BGRAText, BGRATextFX, BGRAVectorize, BGRAFreeType 9 22 10 This unit provides basic text rendering functions using LCL, and general 11 text definitions. 23 This unit provides basic text rendering functions using LCL. 12 24 13 25 Text functions use a temporary bitmap where the operating system text drawing is used. … … 20 32 21 33 uses 22 Classes, Types, SysUtils, Graphics, BGRABitmapTypes, InterfaceBase, BGRAPen, BGRAGrayscaleMask;34 Classes, Types, SysUtils, BGRAGraphics, BGRABitmapTypes, InterfaceBase, BGRAPen, BGRAGrayscaleMask; 23 35 24 36 type 25 TWordBreakHandler = procedure(var ABeforeUTF8, AAfterUTF8: string) of object;37 TWordBreakHandler = BGRABitmapTypes.TWordBreakHandler; 26 38 27 39 { TCustomLCLFontRenderer } … … 78 90 function BGRAOriginalTextSize(Font: TFont; Quality: TBGRAFontQuality; sUTF8: string; CustomAntialiasingLevel: integer): TSize; 79 91 function BGRAOriginalTextSizeEx(Font: TFont; Quality: TBGRAFontQuality; sUTF8: string; CustomAntialiasingLevel: Integer; out actualAntialiasingLevel: integer): TSize; 80 procedure BGRADefaultWordBreakHandler(var ABefore,AAfter: string);81 92 82 93 function BGRATextUnderline(ATopLeft: TPointF; AWidth: Single; AMetrics: TFontPixelMetric): ArrayOfTPointF; overload; … … 89 100 function FontFullHeightSign: integer; 90 101 function LCLFontAvailable: boolean; 102 function GetFineClearTypeAuto: TBGRAFontQuality; 91 103 92 104 procedure BGRAFillClearTypeGrayscaleMask(dest: TBGRACustomBitmap; x,y: integer; xThird: integer; mask: TGrayscaleMask; color: TBGRAPixel; texture: IBGRAScanner = nil; RGBOrder: boolean=true); 93 105 procedure BGRAFillClearTypeMask(dest: TBGRACustomBitmap; x,y: integer; xThird: integer; mask: TBGRACustomBitmap; color: TBGRAPixel; texture: IBGRAScanner = nil; RGBOrder: boolean=true); 94 106 procedure BGRAFillClearTypeRGBMask(dest: TBGRACustomBitmap; x,y: integer; mask: TBGRACustomBitmap; color: TBGRAPixel; texture: IBGRAScanner = nil; KeepRGBOrder: boolean=true); 95 procedure BGRAInternalRenderText(dest: TBGRACustomBitmap; Quality: TBGRAFontQuality; grayscale: TGrayscaleMask; temp: TBGRACustomBitmap; 96 x,y,xThird: integer; c: TBGRAPixel; tex: IBGRAScanner); 97 98 const FontAntialiasingLevel = {$IFDEF LINUX}3{$ELSE}6{$ENDIF}; //linux rendering is already great 107 108 const FontAntialiasingLevel = {$IFDEF LCL_RENDERER_IS_FINE}3{$ELSE}6{$ENDIF}; 99 109 const FontDefaultQuality = fqAntialiased; 100 110 101 function GetFontPixelMetric(AFont: TFont): TFontPixelMetric; 111 function GetLCLFontPixelMetric(AFont: TFont): TFontPixelMetric; 112 113 var 114 BGRATextOutImproveReadabilityProc : procedure (bmp: TBGRACustomBitmap; AFont: TFont; xf,yf: single; text: string; color: TBGRAPixel; tex: IBGRAScanner; align: TAlignment; mode : TBGRATextOutImproveReadabilityMode); 102 115 103 116 implementation 104 117 105 uses GraphType, Math, BGRABlend, LCLProc;118 uses GraphType, Math, BGRABlend, BGRAUTF8; 106 119 107 120 const MaxPixelMetricCount = 100; … … 110 123 LCLFontDisabledValue: boolean; 111 124 TempBmp: TBitmap; 125 fqFineClearTypeComputed: boolean; 126 fqFineClearTypeValue: TBGRAFontQuality; 112 127 FontHeightSignComputed: boolean; 113 128 FontHeightSignValue: integer; … … 264 279 end; 265 280 266 function Get FontPixelMetric(AFont: TFont): TFontPixelMetric;281 function GetLCLFontPixelMetric(AFont: TFont): TFontPixelMetric; 267 282 var i,startPos,endPos: integer; 268 283 begin … … 376 391 end; 377 392 393 function GetFineClearTypeAuto: TBGRAFontQuality; 394 var 395 lclBmp: TBitmap; 396 bgra: TBGRACustomBitmap; 397 x,y: integer; 398 begin 399 if fqFineClearTypeComputed then 400 begin 401 result:= fqFineClearTypeValue; 402 exit; 403 end; 404 result := fqFineAntialiasing; 405 if not LCLFontDisabledValue and not (WidgetSet.LCLPlatform = lpNoGUI) then 406 begin 407 lclBmp := TBitmap.Create; 408 lclBmp.Canvas.FillRect(0,0,lclBmp.Width,lclBmp.Height); 409 lclBmp.Canvas.Font.Height := -50; 410 lclBmp.Canvas.Font.Quality := fqCleartype; 411 with lclBmp.Canvas.TextExtent('/') do 412 begin 413 lclBmp.Width := cx; 414 lclBmp.Height := cy; 415 end; 416 lclBmp.Canvas.TextOut(0,0,'/'); 417 bgra:= BGRABitmapFactory.Create(lclBmp); 418 x:= bgra.Width div 2; 419 for y := 0 to bgra.Height-1 do 420 with bgra.GetPixel(x,y) do 421 if (red<>blue) then 422 begin 423 if blue < red then 424 result:= fqFineClearTypeRGB 425 else 426 result:= fqFineClearTypeBGR; 427 break; 428 end else 429 if (green = 0) then break; 430 lclBmp.Free; 431 end; 432 fqFineClearTypeValue := result; 433 fqFineClearTypeComputed:= true; 434 end; 435 378 436 function FontEmHeightSign: integer; 379 437 begin … … 390 448 if not FontHeightSignComputed then GetFontHeightSign; 391 449 result := not LCLFontDisabledValue; 392 end;393 394 procedure BGRAFillClearTypeMaskPtr(dest: TBGRACustomBitmap; x,y: integer; xThird: integer; maskData: PByte; maskPixelSize: NativeInt; maskRowSize: NativeInt; maskWidth,maskHeight: integer; color: TBGRAPixel; texture: IBGRAScanner; RGBOrder: boolean);395 var396 pdest: PBGRAPixel;397 ClearTypePixel: array[0..2] of byte;398 curThird: integer;399 400 procedure OutputPixel; inline;401 begin402 if texture <> nil then403 color := texture.ScanNextPixel;404 if RGBOrder then405 ClearTypeDrawPixel(pdest, ClearTypePixel[0],ClearTypePixel[1],ClearTypePixel[2], color)406 else407 ClearTypeDrawPixel(pdest, ClearTypePixel[2],ClearTypePixel[1],ClearTypePixel[0], color);408 end;409 410 procedure NextAlpha(alphaValue: byte); inline;411 begin412 ClearTypePixel[curThird] := alphaValue;413 inc(curThird);414 if curThird = 3 then415 begin416 OutputPixel;417 curThird := 0;418 Fillchar(ClearTypePixel, sizeof(ClearTypePixel),0);419 inc(pdest);420 end;421 end;422 423 procedure EndRow; inline;424 begin425 if curThird > 0 then OutputPixel;426 end;427 428 var429 yMask,n: integer;430 a: byte;431 pmask: PByte;432 dx:integer;433 miny,maxy,minx,minxThird,maxx,alphaMinX,alphaMaxX,alphaLineLen: integer;434 leftOnSide, rightOnSide: boolean;435 countBetween: integer;436 v1,v2,v3: byte;437 438 procedure StartRow; inline;439 begin440 pdest := dest.Scanline[yMask+y]+minx;441 if texture <> nil then442 texture.ScanMoveTo(minx,yMask+y);443 444 curThird := minxThird;445 ClearTypePixel[0] := 0;446 ClearTypePixel[1] := 0;447 ClearTypePixel[2] := 0;448 end;449 450 begin451 alphaLineLen := maskWidth+2;452 453 xThird -= 1; //for first subpixel454 455 if xThird >= 0 then dx := xThird div 3456 else dx := -((-xThird+2) div 3);457 x += dx;458 xThird -= dx*3;459 460 if y >= dest.ClipRect.Top then miny := 0461 else miny := dest.ClipRect.Top-y;462 if y+maskHeight-1 < dest.ClipRect.Bottom then463 maxy := maskHeight-1 else464 maxy := dest.ClipRect.Bottom-1-y;465 466 if x >= dest.ClipRect.Left then467 begin468 minx := x;469 minxThird := xThird;470 alphaMinX := 0;471 leftOnSide := false;472 end else473 begin474 minx := dest.ClipRect.Left;475 minxThird := 0;476 alphaMinX := (dest.ClipRect.Left-x)*3 - xThird;477 leftOnSide := true;478 end;479 480 if x*3+xThird+maskWidth-1 < dest.ClipRect.Right*3 then481 begin482 maxx := (x*3+xThird+maskWidth-1) div 3;483 alphaMaxX := alphaLineLen-1;484 rightOnSide := false;485 end else486 begin487 maxx := dest.ClipRect.Right-1;488 alphaMaxX := maxx*3+2 - (x*3+xThird);489 rightOnSide := true;490 end;491 492 countBetween := alphaMaxX-alphaMinX-1;493 494 if (alphaMinX <= alphaMaxX) then495 begin496 for yMask := miny to maxy do497 begin498 StartRow;499 500 if leftOnSide then501 begin502 pmask := maskData + (yMask*maskRowSize)+ (alphaMinX-1)*maskPixelSize;503 a := pmask^ div 3;504 v1 := a+a;505 v2 := a;506 v3 := 0;507 inc(pmask, maskPixelSize);508 end else509 begin510 pmask := maskData + (yMask*maskRowSize);511 v1 := 0;512 v2 := 0;513 v3 := 0;514 end;515 516 for n := countBetween-1 downto 0 do517 begin518 a := pmask^ div 3;519 v1 += a;520 v2 += a;521 v3 += a;522 inc(pmask, maskPixelSize);523 524 NextAlpha(v1);525 v1 := v2;526 v2 := v3;527 v3 := 0;528 end;529 530 if rightOnSide then531 begin532 a := pmask^ div 3;533 v1 += a;534 v2 += a+a;535 end;536 537 NextAlpha(v1);538 NextAlpha(v2);539 540 EndRow;541 end;542 end;543 450 end; 544 451 … … 546 453 y: integer; xThird: integer; mask: TGrayscaleMask; color: TBGRAPixel; 547 454 texture: IBGRAScanner; RGBOrder: boolean); 548 var delta: NativeInt; 549 begin 550 delta := mask.Width; 551 BGRAFillClearTypeMaskPtr(dest,x,y,xThird,mask.ScanLine[0],1,delta,mask.Width,mask.Height,color,texture,RGBOrder); 455 begin 456 BGRAGrayscaleMask.BGRAFillClearTypeGrayscaleMask(dest,x,y,xThird,mask,color,texture,RGBOrder); 552 457 end; 553 458 554 459 procedure BGRAFillClearTypeMask(dest: TBGRACustomBitmap; x,y: integer; xThird: integer; mask: TBGRACustomBitmap; color: TBGRAPixel; texture: IBGRAScanner; RGBOrder: boolean); 555 var delta: NativeInt; 556 begin 557 delta := mask.Width*sizeof(TBGRAPixel); 558 if mask.LineOrder = riloBottomToTop then 559 delta := -delta; 560 BGRAFillClearTypeMaskPtr(dest,x,y,xThird,pbyte(mask.ScanLine[0])+1,sizeof(TBGRAPixel),delta,mask.Width,mask.Height,color,texture,RGBOrder); 460 begin 461 BGRABlend.BGRAFillClearTypeMask(dest,x,y,xThird,mask,color,texture,RGBOrder); 561 462 end; 562 463 … … 564 465 mask: TBGRACustomBitmap; color: TBGRAPixel; texture: IBGRAScanner; 565 466 KeepRGBOrder: boolean); 566 var 567 minx,miny,maxx,maxy,countx,n,yb: integer; 568 pdest,psrc: PBGRAPixel; 569 begin 570 if y >= dest.ClipRect.Top then miny := 0 571 else miny := dest.ClipRect.Top-y; 572 if y+mask.Height-1 < dest.ClipRect.Bottom then 573 maxy := mask.Height-1 else 574 maxy := dest.ClipRect.Bottom-1-y; 575 576 if x >= dest.ClipRect.Left then minx := 0 577 else minx := dest.ClipRect.Left-x; 578 if x+mask.Width-1 < dest.ClipRect.Right then 579 maxx := mask.Width-1 else 580 maxx := dest.ClipRect.Right-1-x; 581 582 countx := maxx-minx+1; 583 if countx <= 0 then exit; 584 585 for yb := miny to maxy do 586 begin 587 pdest := dest.ScanLine[y+yb]+(x+minx); 588 psrc := mask.ScanLine[yb]+minx; 589 if texture <> nil then 590 texture.ScanMoveTo(x+minx, y+yb); 591 if KeepRGBOrder then 592 begin 593 for n := countx-1 downto 0 do 594 begin 595 if texture <> nil then color := texture.ScanNextPixel; 596 ClearTypeDrawPixel(pdest, psrc^.red, psrc^.green, psrc^.blue, color); 597 inc(pdest); 598 inc(psrc); 599 end; 600 end else 601 begin 602 for n := countx-1 downto 0 do 603 begin 604 if texture <> nil then color := texture.ScanNextPixel; 605 ClearTypeDrawPixel(pdest, psrc^.blue, psrc^.green, psrc^.red, color); 606 inc(pdest); 607 inc(psrc); 608 end; 609 end; 610 end; 467 begin 468 BGRABlend.BGRAFillClearTypeRGBMask(dest,x,y,mask,color,texture,KeepRGBOrder); 611 469 end; 612 470 … … 649 507 end; 650 508 651 procedure BGRADefaultWordBreakHandler(var ABefore, AAfter: string);652 var p: integer;653 begin654 if (AAfter <> '') and (ABefore <> '') and (AAfter[1]<> ' ') and (ABefore[length(ABefore)] <> ' ') then655 begin656 p := length(ABefore);657 while (p > 1) and (ABefore[p-1] <> ' ') do dec(p);658 if p > 1 then //can put the word after659 begin660 AAfter := copy(ABefore,p,length(ABefore)-p+1)+AAfter;661 ABefore := copy(ABefore,1,p-1);662 end else663 begin //cannot put the word after, so before664 665 end;666 end;667 while (ABefore <> '') and (ABefore[length(ABefore)] =' ') do delete(ABefore,length(ABefore),1);668 while (AAfter <> '') and (AAfter[1] =' ') do delete(AAfter,1,1);669 end;670 671 509 function BGRATextSize(Font: TFont; Quality: TBGRAFontQuality; sUTF8: string; CustomAntialiasingLevel: Integer): TSize; 672 510 begin … … 735 573 736 574 function CleanTextOutString(s: string): string; 737 var idxIn, idxOut: integer; 738 begin 739 setlength(result, length(s)); 740 idxIn := 1; 741 idxOut := 1; 742 while IdxIn <= length(s) do 743 begin 744 if not (s[idxIn] in[#13,#10,#9]) then //those characters are always 1 byte long so it is the same with UTF8 745 begin 746 result[idxOut] := s[idxIn]; 747 inc(idxOut); 748 end; 749 inc(idxIn); 750 end; 751 setlength(result, idxOut-1); 575 begin 576 result := BGRABitmapTypes.CleanTextOutString(s); 752 577 end; 753 578 754 579 function RemoveLineEnding(var s: string; indexByte: integer): boolean; 755 begin //we can ignore UTF8 character length because #13 and #10 are always 1 byte long 756 //so this function can be applied to UTF8 strings as well 757 result := false; 758 if length(s) >= indexByte then 759 begin 760 if s[indexByte] in[#13,#10] then 761 begin 762 result := true; 763 if length(s) >= indexByte+1 then 764 begin 765 if (s[indexByte+1] <> s[indexByte]) and (s[indexByte+1] in[#13,#10]) then 766 delete(s,indexByte,2) 767 else 768 delete(s,indexByte,1); 769 end 770 else 771 delete(s,indexByte,1); 772 end; 773 end; 580 begin 581 result := BGRABitmapTypes.RemoveLineEnding(s, indexByte); 774 582 end; 775 583 776 584 function RemoveLineEndingUTF8(var sUTF8: string; indexUTF8: integer): boolean; 777 var indexByte: integer; 778 pIndex: PChar; 779 begin 780 pIndex := UTF8CharStart(@sUTF8[1],length(sUTF8),indexUTF8); 781 if pIndex = nil then 782 begin 783 result := false; 784 exit; 785 end; 786 indexByte := pIndex - @sUTF8[1]; 787 result := RemoveLineEnding(sUTF8, indexByte); 585 begin 586 result := BGRABitmapTypes.RemoveLineEndingUTF8(sUTF8,indexUTF8); 788 587 end; 789 588 … … 816 615 size: TSize; 817 616 temp: TBGRACustomBitmap; 617 {$IFDEF RENDER_TEXT_ON_TBITMAP} 618 tempLCL: TBitmap; 619 {$ENDIF} 818 620 xMargin,xThird: integer; 819 621 tempSize: TSize; … … 835 637 end; 836 638 639 {$IFDEF LCL_RENDERER_IS_FINE} 640 if (Quality in [fqFineAntialiasing, fqFineClearTypeRGB, fqFineClearTypeBGR]) and 641 (BGRATextSize(Font, fqSystem, 'Hg', 1).cy >= 13) then 642 begin 643 if Quality = fqFineAntialiasing then Quality := fqSystem; 644 {$IFDEF LCL_CLEARTYPE_RENDERER_IS_FINE} 645 if Quality = GetFineClearTypeAuto then Quality := fqSystemClearType; 646 {$ENDIF} 647 end; 648 {$ENDIF} 649 837 650 size := BGRAOriginalTextSizeEx(Font,Quality,sUTF8,CustomAntialiasingLevel,sizeFactor); 838 651 if (size.cx = 0) or (size.cy = 0) then … … 890 703 tempSize.cx += xMargin*2; 891 704 705 {$IFDEF RENDER_TEXT_ON_TBITMAP} 706 tempLCL := TBitmap.Create; 707 tempLCL.Width := tempSize.cx; 708 tempLCL.Height := tempSize.cy; 709 tempLCL.Canvas.Brush.Color := clBlack; 710 tempLCL.Canvas.FillRect(0,0,tempLCL.Width,tempLCL.Height); 711 with tempLCL do begin 712 {$ELSE} 892 713 temp := bmp.NewBitmap(tempSize.cx, tempSize.cy, BGRABlack); 893 temp.Canvas.Font := Font; 894 temp.Canvas.Font.Height := Font.Height*sizeFactor; 895 temp.Canvas.Font.Color := clWhite; 896 temp.Canvas.Brush.Style := bsClear; 897 temp.Canvas.TextOut(xMargin+subX, subY, sUTF8); 714 with temp do begin 715 {$ENDIF} 716 Canvas.Font := Font; 717 Canvas.Font.Height := Font.Height*sizeFactor; 718 Canvas.Font.Color := clWhite; 719 Canvas.Brush.Style := bsClear; 720 Canvas.TextOut(xMargin+subX, subY, sUTF8); 721 end; 722 {$IFDEF RENDER_TEXT_ON_TBITMAP} 723 temp := BGRABitmapFactory.create(tempLCL,False); 724 tempLCL.Free; 725 {$ENDIF} 898 726 899 727 FilterOriginalText(Quality,CustomAntialiasingLevel, temp, grayscale); … … 921 749 oldOrientation: integer; 922 750 grayscale:TGrayscaleMask; 751 {$IFDEF RENDER_TEXT_ON_TBITMAP} 752 tempLCL: TBitmap; 753 {$ENDIF} 923 754 924 755 procedure rotBoundsAdd(pt: TPointF); … … 994 825 if deltaY <> 0 then rotBounds.Bottom += sizeFactor; 995 826 827 {$IFDEF RENDER_TEXT_ON_TBITMAP} 828 tempLCL := TBitmap.Create; 829 tempLCL.Width := rotBounds.Right-rotBounds.Left; 830 tempLCL.Height := rotBounds.Bottom-rotBounds.Top; 831 tempLCL.Canvas.Brush.Color := clBlack; 832 tempLCL.Canvas.FillRect(0,0,tempLCL.Width,tempLCL.Height); 833 with tempLCL do begin 834 {$ELSE} 996 835 temp := bmp.NewBitmap(rotBounds.Right-rotBounds.Left,rotBounds.Bottom-rotBounds.Top, BGRABlack); 997 temp.Canvas.Font := Font; 998 temp.Canvas.Font.Color := clWhite; 999 temp.Canvas.Font.Orientation := orientationTenthDegCCW; 1000 temp.Canvas.Font.Height := round(Font.Height*sizeFactor); 1001 temp.Canvas.Brush.Style := bsClear; 1002 temp.Canvas.TextOut(-rotBounds.Left+deltaX, -rotBounds.Top+deltaY, sUTF8); 836 with temp do begin 837 {$ENDIF} 838 Canvas.Font := Font; 839 Canvas.Font.Color := clWhite; 840 Canvas.Font.Orientation := orientationTenthDegCCW; 841 Canvas.Font.Height := round(Font.Height*sizeFactor); 842 Canvas.Brush.Style := bsClear; 843 Canvas.TextOut(-rotBounds.Left+deltaX, -rotBounds.Top+deltaY, sUTF8); 844 end; 845 {$IFDEF RENDER_TEXT_ON_TBITMAP} 846 temp := BGRABitmapFactory.create(tempLCL,False); 847 tempLCL.Free; 848 {$ENDIF} 1003 849 1004 850 FilterOriginalText(Quality,CustomAntialiasingLevel,temp,grayscale); … … 1017 863 cr: TRect; 1018 864 grayscale:TGrayscaleMask; 865 {$IFDEF RENDER_TEXT_ON_TBITMAP} 866 tempLCL: TBitmap; 867 {$ENDIF} 1019 868 begin 1020 869 if not LCLFontAvailable then exit; … … 1038 887 exit; 1039 888 889 {$IFDEF LCL_RENDERER_IS_FINE} 890 if (Quality in [fqFineAntialiasing, fqFineClearTypeRGB, fqFineClearTypeBGR]) and 891 (BGRATextSize(Font, fqSystem, 'Hg', 1).cy >= 13) then 892 begin 893 if Quality = fqFineAntialiasing then Quality := fqSystem; 894 {$IFDEF LCL_CLEARTYPE_RENDERER_IS_FINE} 895 if Quality = GetFineClearTypeAuto then Quality := fqSystemClearType; 896 {$ENDIF} 897 end; 898 {$ENDIF} 899 1040 900 if Quality in[fqFineAntialiasing,fqFineClearTypeBGR,fqFineClearTypeRGB] then 1041 901 sizeFactor := CustomAntialiasingLevel … … 1043 903 sizeFactor := 1; 1044 904 905 {$IFDEF RENDER_TEXT_ON_TBITMAP} 906 tempLCL := TBitmap.Create; 907 tempLCL.Width := tx*sizeFactor; 908 tempLCL.Height := ty*sizeFactor; 909 tempLCL.Canvas.Brush.Color := clBlack; 910 tempLCL.Canvas.FillRect(0,0,tempLCL.Width,tempLCL.Height); 911 with tempLCL do begin 912 {$ELSE} 1045 913 temp := bmp.NewBitmap(tx*sizeFactor, ty*sizeFactor, BGRABlack); 1046 temp.Canvas.Font := Font; 1047 temp.Canvas.Font.Orientation := 0; 1048 if Quality in[fqFineAntialiasing,fqFineClearTypeBGR,fqFineClearTypeRGB] then temp.Canvas.Font.Height := Font.Height*CustomAntialiasingLevel 1049 else temp.Canvas.Font.Height := Font.Height; 1050 temp.Canvas.Font.Color := clWhite; 1051 temp.Canvas.Brush.Style := bsClear; 1052 temp.Canvas.TextRect(rect(lim.Left-ARect.Left, lim.Top-ARect.Top, (ARect.Right-ARect.Left)*sizeFactor, (ARect.Bottom-ARect.Top)*sizeFactor), (x - lim.Left)*sizeFactor, (y - lim.Top)*sizeFactor, sUTF8, style); 914 with temp do begin 915 {$ENDIF} 916 Canvas.Font := Font; 917 Canvas.Font.Orientation := 0; 918 if Quality in[fqFineAntialiasing,fqFineClearTypeBGR,fqFineClearTypeRGB] then Canvas.Font.Height := Font.Height*CustomAntialiasingLevel 919 else Canvas.Font.Height := Font.Height; 920 Canvas.Font.Color := clWhite; 921 Canvas.Brush.Style := bsClear; 922 Canvas.TextRect(rect(lim.Left-ARect.Left, lim.Top-ARect.Top, (ARect.Right-ARect.Left)*sizeFactor, (ARect.Bottom-ARect.Top)*sizeFactor), (x - lim.Left)*sizeFactor, (y - lim.Top)*sizeFactor, sUTF8, style); 923 end; 924 {$IFDEF RENDER_TEXT_ON_TBITMAP} 925 temp := BGRABitmapFactory.create(tempLCL,False); 926 tempLCL.Free; 927 {$ENDIF} 1053 928 1054 929 FilterOriginalText(Quality,CustomAntialiasingLevel,temp,grayscale); … … 1163 1038 UpdateFont; 1164 1039 if FontQuality in[fqSystem,fqSystemClearType] then 1165 result := BGRAText.GetFontPixelMetric(FFont)1040 result := GetLCLFontPixelMetric(FFont) 1166 1041 else 1167 1042 begin … … 1169 1044 FxFont.Assign(FFont); 1170 1045 FxFont.Height := fxFont.Height*FontAntialiasingLevel; 1171 Result:= BGRAText.GetFontPixelMetric(FxFont);1046 Result:= GetLCLFontPixelMetric(FxFont); 1172 1047 if Result.Baseline <> -1 then Result.Baseline:= round((Result.Baseline-1)/FontAntialiasingLevel); 1173 1048 if Result.CapLine <> -1 then Result.CapLine:= round(Result.CapLine/FontAntialiasingLevel); … … 1354 1229 1355 1230 function TCustomLCLFontRenderer.TextSize(sUTF8: string): TSize; 1356 begin 1231 var oldOrientation: integer; 1232 begin 1233 oldOrientation:= FontOrientation; 1234 FontOrientation:= 0; 1357 1235 UpdateFont; 1358 1236 result := TextSizeNoUpdateFont(sUTF8); 1237 FontOrientation:= oldOrientation; 1359 1238 end; 1360 1239
Note:
See TracChangeset
for help on using the changeset viewer.