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

Legend:

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

    r472 r494  
    1111  to draw text like TBGRABitmap.TextOut will use the chosen renderer.
    1212
    13   >> Note that you need to defined the default FreeType font collection
    14   >> using LazFreeTypeFontCollection unit.
     13  >> Note that you need to define the default FreeType font collection
     14  >> using EasyLazFreeType unit.
    1515
    1616  To set the effects, keep a variable containing
     
    2626interface
    2727
     28{$i bgrabitmap.inc}
     29
    2830uses
    29   Types, Classes, SysUtils, Graphics, BGRABitmapTypes, EasyLazFreeType, FPimage, BGRAText, BGRATextFX, BGRAPhongTypes, LCLVersion;
     31  Types, Classes, SysUtils, BGRAGraphics, BGRABitmapTypes, EasyLazFreeType, FPimage,
     32  BGRACustomTextFX, BGRAPhongTypes;
    3033
    3134type
     
    5760    ShadowRadius: integer;
    5861    ShadowOffset: TPoint;
     62    ShadowQuality: TRadialBlurType;
    5963
    6064    OutlineColor: TBGRAPixel;
     
    101105    ShadowRadius: integer;
    102106    ShadowOffset: TPoint;
     107    ShadowQuality: TRadialBlurType;
    103108
    104109    OutlineColor: TBGRAPixel;
     
    110115    procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel); overload;
    111116    procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel; AAlign: TFreeTypeAlignments); overload;
    112     function CreateTextEffect(AText: string; AFont: TFreeTypeRenderableFont): TBGRATextEffect;
     117    { If this code does not compile, you probably have an older version of Lazarus. To fix the problem,
     118      go into "bgrabitmap.inc" and comment the compiler directives }
     119    {$IFDEF BGRABITMAP_USE_LCL12}
     120    procedure DrawTextWordBreak(AText: string; AFont: TFreeTypeRenderableFont; x, y, AMaxWidth: Single; AColor: TBGRAPixel; AAlign: TFreeTypeAlignments); overload;
     121    procedure DrawTextRect(AText: string; AFont: TFreeTypeRenderableFont; X1,Y1,X2,Y2: Single; AColor: TBGRAPixel; AAlign: TFreeTypeAlignments); overload;
     122    {$ENDIF}
     123    {$IFDEF BGRABITMAP_USE_LCL15}
     124    procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TFPColor); override; overload;
     125    procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel); overload;
     126    procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel; AAlign: TFreeTypeAlignments); overload;
     127    {$ENDIF}
     128    function CreateTextEffect(AText: string; AFont: TFreeTypeRenderableFont): TBGRACustomTextEffect;
    113129    destructor Destroy; override;
    114130  end;
     
    117133implementation
    118134
    119 uses LCLType, BGRABlend, Math;
     135uses BGRABlend, Math;
    120136
    121137{ TBGRAFreeTypeFontRenderer }
     
    133149  result.ShadowRadius := ShadowRadius;
    134150  result.ShadowVisible := ShadowVisible;
     151  result.ShadowQuality := ShadowQuality;
    135152  result.ClearTypeRGBOrder := FontQuality <> fqFineClearTypeBGR;
    136153  result.Destination := ASurface;
     
    159176procedure TBGRAFreeTypeFontRenderer.UpdateFont;
    160177var fts: TFreeTypeStyles;
     178  filename: string;
    161179begin
    162180  fts := [];
     
    164182  if fsItalic in FontStyle then fts += [ftsItalic];
    165183  try
    166     {$IF (lcl_fullversion>=1010000)}
    167     FFont.SetNameAndStyle(FontName,fts);
     184    filename := FontName;
     185    {$IFDEF BGRABITMAP_USE_LCL12}
     186    FFont.SetNameAndStyle(filename,fts);
    168187    {$ELSE}
    169     FFont.Name := FontName;
     188    FFont.Name := filename;
    170189    FFont.Style := fts;
    171190    {$ENDIF}
     
    202221  end;
    203222  FFont.Hinted := FontHinted;
    204   {$IF (lcl_fullversion>=1010000)}
    205   FFont.StrikeOutDecoration := fsStrikeOut in FontStyle;
    206   FFont.UnderlineDecoration := fsUnderline in FontStyle;
     223  {$IFDEF BGRABITMAP_USE_LCL12}
     224    FFont.StrikeOutDecoration := fsStrikeOut in FontStyle;
     225    FFont.UnderlineDecoration := fsUnderline in FontStyle;
    207226  {$ENDIF}
    208227end;
     
    220239  ShadowOffset := Point(5,5);
    221240  ShadowRadius := 5;
     241  ShadowQuality:= rbFast;
    222242end;
    223243
     
    303323  end;
    304324  case style.Layout of
    305   {$IF (lcl_fullversion>=1010000)}
    306   tlCenter: begin ARect.Top := y; align += [ftaVerticalCenter]; end;
     325  {$IFDEF BGRABITMAP_USE_LCL12}
     326    tlCenter: begin ARect.Top := y; align += [ftaVerticalCenter]; end;
    307327  {$ENDIF}
    308328  tlBottom: begin ARect.top := y; align += [ftaBottom]; end;
     
    310330  end;
    311331  try
    312     {$IF (lcl_fullversion>=1010000)}
    313     if style.Wordbreak then
    314       GetDrawer(ADest).DrawTextRect(s, FFont, ARect.Left,ARect.Top,ARect.Right,ARect.Bottom,BGRAToFPColor(c),align)
    315     else
     332    {$IFDEF BGRABITMAP_USE_LCL12}
     333      if style.Wordbreak then
     334        GetDrawer(ADest).DrawTextRect(s, FFont, ARect.Left,ARect.Top,ARect.Right,ARect.Bottom,BGRAToFPColor(c),align)
     335      else
    316336    {$ENDIF}
    317337    begin
     
    345365function TBGRAFreeTypeFontRenderer.TextSize(s: string): TSize;
    346366begin
     367  UpdateFont;
    347368  result.cx := round(FFont.TextWidth(s));
    348369  result.cy := round(FFont.LineFullHeight);
     
    457478  ClearTypeRGBOrder:= true;
    458479  ShaderActive := true;
     480  ShadowQuality:= rbFast;
    459481end;
    460482
    461483procedure TBGRAFreeTypeDrawer.DrawText(AText: string;
    462484  AFont: TFreeTypeRenderableFont; x, y: single; AColor: TFPColor);
    463 var fx: TBGRATextEffect;
     485var fx: TBGRACustomTextEffect;
    464486  procedure DoOutline;
    465487  begin
     
    476498  begin
    477499    fx := CreateTextEffect(AText, AFont);
     500    fx.ShadowQuality := ShadowQuality;
    478501    y -= AFont.Ascent;
    479502    if ShadowActuallyVisible then fx.DrawShadow(Destination, round(x+ShadowOffset.X),round(y+ShadowOffset.Y), ShadowRadius, ShadowColor);
     
    518541end;
    519542
     543{$IFDEF BGRABITMAP_USE_LCL12}
     544procedure TBGRAFreeTypeDrawer.DrawTextWordBreak(AText: string;
     545  AFont: TFreeTypeRenderableFont; x, y, AMaxWidth: Single; AColor: TBGRAPixel;
     546  AAlign: TFreeTypeAlignments);
     547begin
     548  DrawTextWordBreak(AText,AFont,x,y,AMaxWidth,BGRAToFPColor(AColor),AAlign);
     549end;
     550
     551procedure TBGRAFreeTypeDrawer.DrawTextRect(AText: string;
     552  AFont: TFreeTypeRenderableFont; X1, Y1, X2, Y2: Single; AColor: TBGRAPixel;
     553  AAlign: TFreeTypeAlignments);
     554begin
     555  DrawTextRect(AText,AFont,X1,Y1,X2,Y2,BGRAToFPColor(AColor),AAlign);
     556end;
     557{$ENDIF}
     558
     559{$IFDEF BGRABITMAP_USE_LCL15}
     560procedure TBGRAFreeTypeDrawer.DrawGlyph(AGlyph: integer;
     561  AFont: TFreeTypeRenderableFont; x, y: single; AColor: TFPColor);
     562var f: TFreeTypeFont;
     563begin
     564  if not (AFont is TFreeTypeFont) then exit;
     565  f := TFreeTypeFont(Afont);
     566  FColor := FPColorToBGRA(AColor);
     567  if AFont.ClearType then
     568    f.RenderGlyph(AGlyph, x, y, Destination.ClipRect, @RenderDirectlyClearType)
     569  else
     570    f.RenderGlyph(AGlyph, x, y, Destination.ClipRect, @RenderDirectly);
     571end;
     572
     573procedure TBGRAFreeTypeDrawer.DrawGlyph(AGlyph: integer;
     574  AFont: TFreeTypeRenderableFont; x, y: single; AColor: TBGRAPixel);
     575begin
     576  DrawGlyph(AGlyph, AFont, x,y, BGRAToFPColor(AColor));
     577end;
     578
     579procedure TBGRAFreeTypeDrawer.DrawGlyph(AGlyph: integer;
     580  AFont: TFreeTypeRenderableFont; x, y: single; AColor: TBGRAPixel;
     581  AAlign: TFreeTypeAlignments);
     582begin
     583  DrawGlyph(AGlyph, AFont, x,y, BGRAToFPColor(AColor), AAlign);
     584end;
     585{$ENDIF}
     586
    520587function TBGRAFreeTypeDrawer.CreateTextEffect(AText: string;
    521   AFont: TFreeTypeRenderableFont): TBGRATextEffect;
     588  AFont: TFreeTypeRenderableFont): TBGRACustomTextEffect;
    522589var
    523590  mask: TBGRACustomBitmap;
     
    545612    AFont.ClearType := tempClearType;
    546613    mask.ConvertToLinearRGB;
    547     result := TBGRATextEffect.Create(mask, true,tx,ty,point(-marginHoriz,-marginVert));
     614    result := TBGRACustomTextEffect.Create(mask, true,tx,ty,point(-marginHoriz,-marginVert));
    548615  finally
    549616    FInCreateTextEffect:= false;
Note: See TracChangeset for help on using the changeset viewer.