Changeset 418 for trunk/Components/CanvasFontManager.pas
- Timestamp:
- Feb 25, 2019, 8:34:42 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/CanvasFontManager.pas
r403 r418 50 50 lMaxCharInc: LONG; 51 51 lMaxDescender: LONG; 52 lEmInc: LONG; 52 53 53 54 destructor Destroy; override; … … 103 104 function AverageCharWidth: longint; 104 105 function MaximumCharWidth: longint; 105 106 function CJKCharWidth: longint; // ALT 107 function CJKTextWidth( const Length: longint; const S: PChar ): longint; 106 108 function IsFixed: boolean; 107 109 … … 391 393 Font.lAveCharWidth := pfm^[ T ].lAveCharWidth; 392 394 Font.lMaxCharInc := pfm^[ T ].lMaxCharInc; 395 Font.lEmInc := pfm^[ T ].lEmInc; 393 396 394 397 Font.ID := -1; // and always shall be so... … … 825 828 Result.lAveCharWidth := FontInfo.lAveCharWidth; 826 829 Result.lMaxCharInc := FontInfo.lMaxCharInc; 830 Result.lEmInc := FontInfo.lEmInc; 827 831 828 832 // Set style flags … … 1060 1064 FCurrentFont.lMaxCharInc := fm.lMaxCharInc; 1061 1065 FCurrentFont.lMaxDescender := fm.lMaxDescender; 1066 FCurrentFont.lEmInc := fm.lEmInc; 1062 1067 end; 1063 1068 … … 1105 1110 Result := FCurrentFont.FixedWidth; 1106 1111 end; 1112 1113 // ALT begins 1114 // 1115 // A 'default' average width for DBCS characters; probably not very accurate. 1116 // Should only be used as a fallback in case querying the actual string width 1117 // is impossible/fails. 1118 // 1119 function TCanvasFontManager.CJKCharWidth: longint; 1120 begin 1121 EnsureMetricsLoaded; 1122 if FCurrentFont.lMaxCharInc < FCurrentFont.lEmInc then 1123 Result := FCurrentFont.lMaxCharInc * FontWidthPrecisionFactor 1124 else 1125 Result := FCurrentFont.lEmInc * FontWidthPrecisionFactor; 1126 end; 1127 1128 // Get the render width of a CJK (Chinese/Japanese/Korean) character string. 1129 // 1130 function TCanvasFontManager.CJKTextWidth( const Length: longint; const S: PChar ): longint; 1131 var 1132 aptl: Array[ 0..TXTBOX_COUNT-1 ] Of PointL; 1133 begin 1134 EnsureMetricsLoaded; 1135 GpiQueryTextBox( FCanvas.Handle, Length, S^, TXTBOX_COUNT, aptl[0] ); 1136 // The pad of 2.1 per character was chosen through experimentation, since the 1137 // actual returned value always seems too narrow. I have no idea why. (ALT) 1138 Result := ( 2.1 + aptl[ TXTBOX_BOTTOMRIGHT ].x) * FontWidthPrecisionFactor; 1139 end; 1140 // 1141 // ALT ends 1107 1142 1108 1143 procedure TCanvasFontManager.DrawString( Var Point: TPoint;
Note:
See TracChangeset
for help on using the changeset viewer.