Changeset 494 for GraphicTest/Packages/bgrabitmap/bgrafreetype.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgrafreetype.pas
r472 r494 11 11 to draw text like TBGRABitmap.TextOut will use the chosen renderer. 12 12 13 >> Note that you need to define dthe default FreeType font collection14 >> using LazFreeTypeFontCollectionunit.13 >> Note that you need to define the default FreeType font collection 14 >> using EasyLazFreeType unit. 15 15 16 16 To set the effects, keep a variable containing … … 26 26 interface 27 27 28 {$i bgrabitmap.inc} 29 28 30 uses 29 Types, Classes, SysUtils, Graphics, BGRABitmapTypes, EasyLazFreeType, FPimage, BGRAText, BGRATextFX, BGRAPhongTypes, LCLVersion; 31 Types, Classes, SysUtils, BGRAGraphics, BGRABitmapTypes, EasyLazFreeType, FPimage, 32 BGRACustomTextFX, BGRAPhongTypes; 30 33 31 34 type … … 57 60 ShadowRadius: integer; 58 61 ShadowOffset: TPoint; 62 ShadowQuality: TRadialBlurType; 59 63 60 64 OutlineColor: TBGRAPixel; … … 101 105 ShadowRadius: integer; 102 106 ShadowOffset: TPoint; 107 ShadowQuality: TRadialBlurType; 103 108 104 109 OutlineColor: TBGRAPixel; … … 110 115 procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel); overload; 111 116 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; 113 129 destructor Destroy; override; 114 130 end; … … 117 133 implementation 118 134 119 uses LCLType,BGRABlend, Math;135 uses BGRABlend, Math; 120 136 121 137 { TBGRAFreeTypeFontRenderer } … … 133 149 result.ShadowRadius := ShadowRadius; 134 150 result.ShadowVisible := ShadowVisible; 151 result.ShadowQuality := ShadowQuality; 135 152 result.ClearTypeRGBOrder := FontQuality <> fqFineClearTypeBGR; 136 153 result.Destination := ASurface; … … 159 176 procedure TBGRAFreeTypeFontRenderer.UpdateFont; 160 177 var fts: TFreeTypeStyles; 178 filename: string; 161 179 begin 162 180 fts := []; … … 164 182 if fsItalic in FontStyle then fts += [ftsItalic]; 165 183 try 166 {$IF (lcl_fullversion>=1010000)} 167 FFont.SetNameAndStyle(FontName,fts); 184 filename := FontName; 185 {$IFDEF BGRABITMAP_USE_LCL12} 186 FFont.SetNameAndStyle(filename,fts); 168 187 {$ELSE} 169 FFont.Name := FontName;188 FFont.Name := filename; 170 189 FFont.Style := fts; 171 190 {$ENDIF} … … 202 221 end; 203 222 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; 207 226 {$ENDIF} 208 227 end; … … 220 239 ShadowOffset := Point(5,5); 221 240 ShadowRadius := 5; 241 ShadowQuality:= rbFast; 222 242 end; 223 243 … … 303 323 end; 304 324 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; 307 327 {$ENDIF} 308 328 tlBottom: begin ARect.top := y; align += [ftaBottom]; end; … … 310 330 end; 311 331 try 312 {$IF (lcl_fullversion>=1010000)}313 if style.Wordbreak then314 GetDrawer(ADest).DrawTextRect(s, FFont, ARect.Left,ARect.Top,ARect.Right,ARect.Bottom,BGRAToFPColor(c),align)315 else332 {$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 316 336 {$ENDIF} 317 337 begin … … 345 365 function TBGRAFreeTypeFontRenderer.TextSize(s: string): TSize; 346 366 begin 367 UpdateFont; 347 368 result.cx := round(FFont.TextWidth(s)); 348 369 result.cy := round(FFont.LineFullHeight); … … 457 478 ClearTypeRGBOrder:= true; 458 479 ShaderActive := true; 480 ShadowQuality:= rbFast; 459 481 end; 460 482 461 483 procedure TBGRAFreeTypeDrawer.DrawText(AText: string; 462 484 AFont: TFreeTypeRenderableFont; x, y: single; AColor: TFPColor); 463 var fx: TBGRA TextEffect;485 var fx: TBGRACustomTextEffect; 464 486 procedure DoOutline; 465 487 begin … … 476 498 begin 477 499 fx := CreateTextEffect(AText, AFont); 500 fx.ShadowQuality := ShadowQuality; 478 501 y -= AFont.Ascent; 479 502 if ShadowActuallyVisible then fx.DrawShadow(Destination, round(x+ShadowOffset.X),round(y+ShadowOffset.Y), ShadowRadius, ShadowColor); … … 518 541 end; 519 542 543 {$IFDEF BGRABITMAP_USE_LCL12} 544 procedure TBGRAFreeTypeDrawer.DrawTextWordBreak(AText: string; 545 AFont: TFreeTypeRenderableFont; x, y, AMaxWidth: Single; AColor: TBGRAPixel; 546 AAlign: TFreeTypeAlignments); 547 begin 548 DrawTextWordBreak(AText,AFont,x,y,AMaxWidth,BGRAToFPColor(AColor),AAlign); 549 end; 550 551 procedure TBGRAFreeTypeDrawer.DrawTextRect(AText: string; 552 AFont: TFreeTypeRenderableFont; X1, Y1, X2, Y2: Single; AColor: TBGRAPixel; 553 AAlign: TFreeTypeAlignments); 554 begin 555 DrawTextRect(AText,AFont,X1,Y1,X2,Y2,BGRAToFPColor(AColor),AAlign); 556 end; 557 {$ENDIF} 558 559 {$IFDEF BGRABITMAP_USE_LCL15} 560 procedure TBGRAFreeTypeDrawer.DrawGlyph(AGlyph: integer; 561 AFont: TFreeTypeRenderableFont; x, y: single; AColor: TFPColor); 562 var f: TFreeTypeFont; 563 begin 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); 571 end; 572 573 procedure TBGRAFreeTypeDrawer.DrawGlyph(AGlyph: integer; 574 AFont: TFreeTypeRenderableFont; x, y: single; AColor: TBGRAPixel); 575 begin 576 DrawGlyph(AGlyph, AFont, x,y, BGRAToFPColor(AColor)); 577 end; 578 579 procedure TBGRAFreeTypeDrawer.DrawGlyph(AGlyph: integer; 580 AFont: TFreeTypeRenderableFont; x, y: single; AColor: TBGRAPixel; 581 AAlign: TFreeTypeAlignments); 582 begin 583 DrawGlyph(AGlyph, AFont, x,y, BGRAToFPColor(AColor), AAlign); 584 end; 585 {$ENDIF} 586 520 587 function TBGRAFreeTypeDrawer.CreateTextEffect(AText: string; 521 AFont: TFreeTypeRenderableFont): TBGRA TextEffect;588 AFont: TFreeTypeRenderableFont): TBGRACustomTextEffect; 522 589 var 523 590 mask: TBGRACustomBitmap; … … 545 612 AFont.ClearType := tempClearType; 546 613 mask.ConvertToLinearRGB; 547 result := TBGRA TextEffect.Create(mask, true,tx,ty,point(-marginHoriz,-marginVert));614 result := TBGRACustomTextEffect.Create(mask, true,tx,ty,point(-marginHoriz,-marginVert)); 548 615 finally 549 616 FInCreateTextEffect:= false;
Note:
See TracChangeset
for help on using the changeset viewer.