Ignore:
Timestamp:
Dec 22, 2016, 8:49:19 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgratext.pas

    r472 r494  
    44
    55interface
     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}
    619
    720{
    821  Font rendering units : BGRAText, BGRATextFX, BGRAVectorize, BGRAFreeType
    922
    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.
    1224
    1325  Text functions use a temporary bitmap where the operating system text drawing is used.
     
    2032
    2133uses
    22   Classes, Types, SysUtils, Graphics, BGRABitmapTypes, InterfaceBase, BGRAPen, BGRAGrayscaleMask;
     34  Classes, Types, SysUtils, BGRAGraphics, BGRABitmapTypes, InterfaceBase, BGRAPen, BGRAGrayscaleMask;
    2335
    2436type
    25   TWordBreakHandler = procedure(var ABeforeUTF8, AAfterUTF8: string) of object;
     37  TWordBreakHandler = BGRABitmapTypes.TWordBreakHandler;
    2638
    2739  { TCustomLCLFontRenderer }
     
    7890function BGRAOriginalTextSize(Font: TFont; Quality: TBGRAFontQuality; sUTF8: string; CustomAntialiasingLevel: integer): TSize;
    7991function BGRAOriginalTextSizeEx(Font: TFont; Quality: TBGRAFontQuality; sUTF8: string; CustomAntialiasingLevel: Integer; out actualAntialiasingLevel: integer): TSize;
    80 procedure BGRADefaultWordBreakHandler(var ABefore,AAfter: string);
    8192
    8293function BGRATextUnderline(ATopLeft: TPointF; AWidth: Single; AMetrics: TFontPixelMetric): ArrayOfTPointF; overload;
     
    89100function FontFullHeightSign: integer;
    90101function LCLFontAvailable: boolean;
     102function GetFineClearTypeAuto: TBGRAFontQuality;
    91103
    92104procedure BGRAFillClearTypeGrayscaleMask(dest: TBGRACustomBitmap; x,y: integer; xThird: integer; mask: TGrayscaleMask; color: TBGRAPixel; texture: IBGRAScanner = nil; RGBOrder: boolean=true);
    93105procedure BGRAFillClearTypeMask(dest: TBGRACustomBitmap; x,y: integer; xThird: integer; mask: TBGRACustomBitmap; color: TBGRAPixel; texture: IBGRAScanner = nil; RGBOrder: boolean=true);
    94106procedure 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
     108const FontAntialiasingLevel = {$IFDEF LCL_RENDERER_IS_FINE}3{$ELSE}6{$ENDIF};
    99109const FontDefaultQuality = fqAntialiased;
    100110
    101 function GetFontPixelMetric(AFont: TFont): TFontPixelMetric;
     111function GetLCLFontPixelMetric(AFont: TFont): TFontPixelMetric;
     112
     113var
     114  BGRATextOutImproveReadabilityProc : procedure (bmp: TBGRACustomBitmap; AFont: TFont; xf,yf: single; text: string; color: TBGRAPixel; tex: IBGRAScanner; align: TAlignment; mode : TBGRATextOutImproveReadabilityMode);
    102115
    103116implementation
    104117
    105 uses GraphType, Math, BGRABlend, LCLProc;
     118uses GraphType, Math, BGRABlend, BGRAUTF8;
    106119
    107120const MaxPixelMetricCount = 100;
     
    110123  LCLFontDisabledValue: boolean;
    111124  TempBmp: TBitmap;
     125  fqFineClearTypeComputed: boolean;
     126  fqFineClearTypeValue: TBGRAFontQuality;
    112127  FontHeightSignComputed: boolean;
    113128  FontHeightSignValue: integer;
     
    264279end;
    265280
    266 function GetFontPixelMetric(AFont: TFont): TFontPixelMetric;
     281function GetLCLFontPixelMetric(AFont: TFont): TFontPixelMetric;
    267282var i,startPos,endPos: integer;
    268283begin
     
    376391end;
    377392
     393function GetFineClearTypeAuto: TBGRAFontQuality;
     394var
     395  lclBmp: TBitmap;
     396  bgra: TBGRACustomBitmap;
     397  x,y: integer;
     398begin
     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;
     434end;
     435
    378436function FontEmHeightSign: integer;
    379437begin
     
    390448  if not FontHeightSignComputed then GetFontHeightSign;
    391449  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 var
    396   pdest: PBGRAPixel;
    397   ClearTypePixel: array[0..2] of byte;
    398   curThird: integer;
    399 
    400   procedure OutputPixel; inline;
    401   begin
    402     if texture <> nil then
    403       color := texture.ScanNextPixel;
    404     if RGBOrder then
    405       ClearTypeDrawPixel(pdest, ClearTypePixel[0],ClearTypePixel[1],ClearTypePixel[2], color)
    406     else
    407       ClearTypeDrawPixel(pdest, ClearTypePixel[2],ClearTypePixel[1],ClearTypePixel[0], color);
    408   end;
    409 
    410   procedure NextAlpha(alphaValue: byte); inline;
    411   begin
    412     ClearTypePixel[curThird] := alphaValue;
    413     inc(curThird);
    414     if curThird = 3 then
    415     begin
    416       OutputPixel;
    417       curThird := 0;
    418       Fillchar(ClearTypePixel, sizeof(ClearTypePixel),0);
    419       inc(pdest);
    420     end;
    421   end;
    422 
    423   procedure EndRow; inline;
    424   begin
    425     if curThird > 0 then OutputPixel;
    426   end;
    427 
    428 var
    429   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   begin
    440     pdest := dest.Scanline[yMask+y]+minx;
    441     if texture <> nil then
    442       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 begin
    451   alphaLineLen := maskWidth+2;
    452 
    453   xThird -= 1; //for first subpixel
    454 
    455   if xThird >= 0 then dx := xThird div 3
    456    else dx := -((-xThird+2) div 3);
    457   x += dx;
    458   xThird -= dx*3;
    459 
    460   if y >= dest.ClipRect.Top then miny := 0
    461     else miny := dest.ClipRect.Top-y;
    462   if y+maskHeight-1 < dest.ClipRect.Bottom then
    463     maxy := maskHeight-1 else
    464       maxy := dest.ClipRect.Bottom-1-y;
    465 
    466   if x >= dest.ClipRect.Left then
    467   begin
    468     minx := x;
    469     minxThird := xThird;
    470     alphaMinX := 0;
    471     leftOnSide := false;
    472   end else
    473   begin
    474     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 then
    481   begin
    482     maxx := (x*3+xThird+maskWidth-1) div 3;
    483     alphaMaxX := alphaLineLen-1;
    484     rightOnSide := false;
    485   end else
    486   begin
    487     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) then
    495   begin
    496     for yMask := miny to maxy do
    497     begin
    498       StartRow;
    499 
    500       if leftOnSide then
    501       begin
    502         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 else
    509       begin
    510         pmask := maskData + (yMask*maskRowSize);
    511         v1 := 0;
    512         v2 := 0;
    513         v3 := 0;
    514       end;
    515 
    516       for n := countBetween-1 downto 0 do
    517       begin
    518         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 then
    531       begin
    532         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;
    543450end;
    544451
     
    546453  y: integer; xThird: integer; mask: TGrayscaleMask; color: TBGRAPixel;
    547454  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);
     455begin
     456  BGRAGrayscaleMask.BGRAFillClearTypeGrayscaleMask(dest,x,y,xThird,mask,color,texture,RGBOrder);
    552457end;
    553458
    554459procedure 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);
     460begin
     461  BGRABlend.BGRAFillClearTypeMask(dest,x,y,xThird,mask,color,texture,RGBOrder);
    561462end;
    562463
     
    564465  mask: TBGRACustomBitmap; color: TBGRAPixel; texture: IBGRAScanner;
    565466  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;
     467begin
     468  BGRABlend.BGRAFillClearTypeRGBMask(dest,x,y,mask,color,texture,KeepRGBOrder);
    611469end;
    612470
     
    649507end;
    650508
    651 procedure BGRADefaultWordBreakHandler(var ABefore, AAfter: string);
    652 var p: integer;
    653 begin
    654   if (AAfter <> '') and (ABefore <> '') and (AAfter[1]<> ' ') and (ABefore[length(ABefore)] <> ' ') then
    655   begin
    656     p := length(ABefore);
    657     while (p > 1) and (ABefore[p-1] <> ' ') do dec(p);
    658     if p > 1 then //can put the word after
    659     begin
    660       AAfter := copy(ABefore,p,length(ABefore)-p+1)+AAfter;
    661       ABefore := copy(ABefore,1,p-1);
    662     end else
    663     begin //cannot put the word after, so before
    664 
    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 
    671509function BGRATextSize(Font: TFont; Quality: TBGRAFontQuality; sUTF8: string; CustomAntialiasingLevel: Integer): TSize;
    672510begin
     
    735573
    736574function 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);
     575begin
     576  result := BGRABitmapTypes.CleanTextOutString(s);
    752577end;
    753578
    754579function 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;
     580begin
     581  result := BGRABitmapTypes.RemoveLineEnding(s, indexByte);
    774582end;
    775583
    776584function 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);
     585begin
     586  result := BGRABitmapTypes.RemoveLineEndingUTF8(sUTF8,indexUTF8);
    788587end;
    789588
     
    816615  size: TSize;
    817616  temp: TBGRACustomBitmap;
     617  {$IFDEF RENDER_TEXT_ON_TBITMAP}
     618  tempLCL: TBitmap;
     619  {$ENDIF}
    818620  xMargin,xThird: integer;
    819621  tempSize: TSize;
     
    835637  end;
    836638
     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
    837650  size := BGRAOriginalTextSizeEx(Font,Quality,sUTF8,CustomAntialiasingLevel,sizeFactor);
    838651  if (size.cx = 0) or (size.cy = 0) then
     
    890703  tempSize.cx += xMargin*2;
    891704
     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}
    892713  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}
    898726
    899727  FilterOriginalText(Quality,CustomAntialiasingLevel, temp, grayscale);
     
    921749  oldOrientation: integer;
    922750  grayscale:TGrayscaleMask;
     751  {$IFDEF RENDER_TEXT_ON_TBITMAP}
     752  tempLCL: TBitmap;
     753  {$ENDIF}
    923754
    924755  procedure rotBoundsAdd(pt: TPointF);
     
    994825  if deltaY <> 0 then rotBounds.Bottom += sizeFactor;
    995826
     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}
    996835  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}
    1003849
    1004850  FilterOriginalText(Quality,CustomAntialiasingLevel,temp,grayscale);
     
    1017863  cr: TRect;
    1018864  grayscale:TGrayscaleMask;
     865  {$IFDEF RENDER_TEXT_ON_TBITMAP}
     866  tempLCL: TBitmap;
     867  {$ENDIF}
    1019868begin
    1020869  if not LCLFontAvailable then exit;
     
    1038887    exit;
    1039888
     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
    1040900  if Quality in[fqFineAntialiasing,fqFineClearTypeBGR,fqFineClearTypeRGB] then
    1041901    sizeFactor := CustomAntialiasingLevel
     
    1043903    sizeFactor := 1;
    1044904
     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}
    1045913  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}
    1053928
    1054929  FilterOriginalText(Quality,CustomAntialiasingLevel,temp,grayscale);
     
    11631038  UpdateFont;
    11641039  if FontQuality in[fqSystem,fqSystemClearType] then
    1165     result := BGRAText.GetFontPixelMetric(FFont)
     1040    result := GetLCLFontPixelMetric(FFont)
    11661041  else
    11671042  begin
     
    11691044    FxFont.Assign(FFont);
    11701045    FxFont.Height := fxFont.Height*FontAntialiasingLevel;
    1171     Result:= BGRAText.GetFontPixelMetric(FxFont);
     1046    Result:= GetLCLFontPixelMetric(FxFont);
    11721047    if Result.Baseline <> -1 then Result.Baseline:= round((Result.Baseline-1)/FontAntialiasingLevel);
    11731048    if Result.CapLine <> -1 then Result.CapLine:= round(Result.CapLine/FontAntialiasingLevel);
     
    13541229
    13551230function TCustomLCLFontRenderer.TextSize(sUTF8: string): TSize;
    1356 begin
     1231var oldOrientation: integer;
     1232begin
     1233  oldOrientation:= FontOrientation;
     1234  FontOrientation:= 0;
    13571235  UpdateFont;
    13581236  result := TextSizeNoUpdateFont(sUTF8);
     1237  FontOrientation:= oldOrientation;
    13591238end;
    13601239
Note: See TracChangeset for help on using the changeset viewer.