Changeset 521 for GraphicTest/Packages/bgrabitmap/bgrafreetype.pas
- Timestamp:
- Apr 17, 2019, 12:58:41 AM (5 years ago)
- Location:
- GraphicTest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest
- Property svn:ignore
-
old new 8 8 GraphicTest.lps 9 9 GraphicTest.dbg 10 heaptrclog.trc
-
- Property svn:ignore
-
GraphicTest/Packages/bgrabitmap/bgrafreetype.pas
r494 r521 51 51 procedure UpdateFont; 52 52 procedure Init; 53 procedure TextOutAnglePatch(ADest: TBGRACustomBitmap; x, y: single; orientation: integer; s: string; 54 c: TBGRAPixel; tex: IBGRAScanner; align: TAlignment); 53 55 public 54 56 FontHinted: boolean; … … 66 68 OutlineTexture: IBGRAScanner; 67 69 68 constructor Create; 69 constructor Create(AShader: TCustomPhongShading; AShaderOwner: boolean); 70 constructor Create; overload; 71 constructor Create(AShader: TCustomPhongShading; AShaderOwner: boolean); overload; 70 72 function GetFontPixelMetric: TFontPixelMetric; override; 71 procedure TextOutAngle({%H-}ADest: TBGRACustomBitmap; {%H-}x, {%H-}y: single; {%H-}orientation: integer; {%H-}s: string; {%H-}c: TBGRAPixel; {%H-}align: TAlignment); override; 72 procedure TextOutAngle({%H-}ADest: TBGRACustomBitmap; {%H-}x, {%H-}y: single; {%H-}orientation: integer; {%H-}s: string; {%H-}texture: IBGRAScanner; {%H-}align: TAlignment); override; 73 procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; s: string; texture: IBGRAScanner; align: TAlignment); override; 74 procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; s: string; c: TBGRAPixel; align: TAlignment); override; 75 procedure TextRect(ADest: TBGRACustomBitmap; ARect: TRect; x, y: integer; s: string; style: TTextStyle; c: TBGRAPixel); override; 76 procedure TextRect(ADest: TBGRACustomBitmap; ARect: TRect; x, y: integer; s: string; style: TTextStyle; texture: IBGRAScanner); override; 77 function TextSize(s: string): TSize; override; 73 procedure TextOutAngle(ADest: TBGRACustomBitmap; x, y: single; orientation: integer; s: string; c: TBGRAPixel; align: TAlignment); overload; override; 74 procedure TextOutAngle(ADest: TBGRACustomBitmap; x, y: single; orientation: integer; s: string; texture: IBGRAScanner; align: TAlignment); overload; override; 75 procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; s: string; texture: IBGRAScanner; align: TAlignment); overload; override; 76 procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; s: string; c: TBGRAPixel; align: TAlignment); overload; override; 77 procedure TextRect(ADest: TBGRACustomBitmap; ARect: TRect; x, y: integer; s: string; style: TTextStyle; c: TBGRAPixel); overload; override; 78 procedure TextRect(ADest: TBGRACustomBitmap; ARect: TRect; x, y: integer; s: string; style: TTextStyle; texture: IBGRAScanner); overload; override; 79 function TextSize(s: string): TSize; overload; override; 80 function TextSize(sUTF8: string; AMaxWidth: integer; {%H-}ARightToLeft: boolean): TSize; overload; override; 81 function TextFitInfo(sUTF8: string; AMaxWidth: integer): integer; override; 78 82 destructor Destroy; override; 79 83 property Collection: TCustomFreeTypeFontCollection read GetCollection; … … 112 116 113 117 constructor Create(ADestination: TBGRACustomBitmap); 114 procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TFPColor); over ride; overload;118 procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TFPColor); overload; override; 115 119 procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel); overload; 116 120 procedure DrawText(AText: string; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel; AAlign: TFreeTypeAlignments); overload; … … 122 126 {$ENDIF} 123 127 {$IFDEF BGRABITMAP_USE_LCL15} 124 procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TFPColor); over ride; overload;128 procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TFPColor); overload; override; 125 129 procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel); overload; 126 130 procedure DrawGlyph(AGlyph: integer; AFont: TFreeTypeRenderableFont; x,y: single; AColor: TBGRAPixel; AAlign: TFreeTypeAlignments); overload; … … 133 137 implementation 134 138 135 uses BGRABlend, Math ;139 uses BGRABlend, Math, BGRATransform; 136 140 137 141 { TBGRAFreeTypeFontRenderer } … … 242 246 end; 243 247 248 procedure TBGRAFreeTypeFontRenderer.TextOutAnglePatch(ADest: TBGRACustomBitmap; 249 x, y: single; orientation: integer; s: string; c: TBGRAPixel; 250 tex: IBGRAScanner; align: TAlignment); 251 const orientationToDeg = -0.1; 252 var 253 temp: TBGRACustomBitmap; 254 coord: TPointF; 255 angleDeg: single; 256 OldOrientation: integer; 257 filter: TResampleFilter; 258 OldFontQuality: TBGRAFontQuality; 259 begin 260 OldOrientation := FontOrientation; 261 FontOrientation:= 0; 262 OldFontQuality := FontQuality; 263 264 if FontQuality in[fqFineClearTypeRGB,fqFineClearTypeBGR] then FontQuality:= fqFineAntialiasing 265 else if FontQuality = fqSystemClearType then FontQuality:= fqSystem; 266 267 temp := BGRABitmapFactory.Create; 268 with TextSize(s) do 269 temp.SetSize(cx,cy); 270 temp.FillTransparent; 271 if tex<>nil then 272 TextOut(temp,0,0, s, tex, taLeftJustify) 273 else 274 TextOut(temp,0,0, s, c, taLeftJustify); 275 276 orientation:= orientation mod 3600; 277 if orientation < 0 then orientation += 3600; 278 279 angleDeg := orientation * orientationToDeg; 280 coord := PointF(x,y); 281 case align of 282 taRightJustify: coord -= AffineMatrixRotationDeg(angleDeg)*PointF(temp.Width,0); 283 taCenter: coord -= AffineMatrixRotationDeg(angleDeg)*PointF(temp.Width,0)*0.5; 284 end; 285 case orientation of 286 0,900,1800,2700: filter := rfBox; 287 else filter := rfCosine; 288 end; 289 ADest.PutImageAngle(coord.x,coord.y, temp, angleDeg, filter); 290 temp.Free; 291 292 FontOrientation:= OldOrientation; 293 FontQuality:= OldFontQuality; 294 end; 295 244 296 constructor TBGRAFreeTypeFontRenderer.Create; 245 297 begin … … 269 321 y: single; orientation: integer; s: string; c: TBGRAPixel; align: TAlignment); 270 322 begin 323 TextOutAnglePatch(ADest, x,y, orientation, s, c, nil, align); 324 {procedure TForm1.TextOutAnglePatch(ADest: TBGRABitmap; 325 x, y: single; orientationTenthDegCCW: integer; 326 s: string; c: TBGRAPixel; AAlign: TAlignment; AResampleFilter: TResampleFilter); 327 const orientationToDeg = -0.1; 328 var 329 temp: TBGRABitmap; 330 coord: TPointF; 331 angleDeg: single; 332 begin 333 temp := TBGRABitmap.Create; 334 ADest.CopyPropertiesTo(temp); 335 temp.FontOrientation := 0; 336 with temp.TextSize(s) do 337 temp.SetSize(cx,cy); 338 temp.FillTransparent; 339 + 340 temp.TextOut(0,0, s, c); 341 342 angleDeg := orientationTenthDegCCW * orientationToDeg; 343 coord := PointF(x,y); 344 case AAlign of 345 taRightJustify: coord -= AffineMatrixRotationDeg(angleDeg)*PointF(temp.Width,0); 346 taCenter: coord -= AffineMatrixRotationDeg(angleDeg)*PointF(temp.Width,0)*0.5; 347 end; 348 349 ADest.PutImageAngle(coord.x,coord.y, temp, angleDeg, rfBox); 350 temp.Free; 351 end; } 271 352 272 353 end; … … 276 357 align: TAlignment); 277 358 begin 278 359 TextOutAnglePatch(ADest, x,y, orientation, s, BGRAPixelTransparent, texture, align); 279 360 end; 280 361 … … 368 449 result.cx := round(FFont.TextWidth(s)); 369 450 result.cy := round(FFont.LineFullHeight); 451 end; 452 453 function TBGRAFreeTypeFontRenderer.TextSize(sUTF8: string; AMaxWidth: integer; 454 ARightToLeft: boolean): TSize; 455 var 456 remains: string; 457 w,h,totalH: single; 458 begin 459 UpdateFont; 460 461 result.cx := 0; 462 totalH := 0; 463 h := FFont.LineFullHeight; 464 repeat 465 FFont.SplitText(sUTF8, AMaxWidth, remains); 466 w := FFont.TextWidth(sUTF8); 467 if round(w)>result.cx then result.cx := round(w); 468 totalH += h; 469 sUTF8 := remains; 470 until remains = ''; 471 result.cy := ceil(totalH); 472 end; 473 474 function TBGRAFreeTypeFontRenderer.TextFitInfo(sUTF8: string; AMaxWidth: integer): integer; 475 var 476 remains: string; 477 begin 478 UpdateFont; 479 FFont.SplitText(sUTF8, AMaxWidth, remains); 480 result := length(sUTF8); 370 481 end; 371 482
Note:
See TracChangeset
for help on using the changeset viewer.