TPostscriptCanvas.ExtentText - Wrong text width calculation winth non-latin characters
Original Reporter info from Mantis: Morganhold
-
Reporter name: Vanya Batalin
Original Reporter info from Mantis: Morganhold
- Reporter name: Vanya Batalin
Description:
Extent text currently can produce only latin characters, and ACSII only from 32 to 128. Actually we cannot get right metrics for some non-latin unicode characters, but we can workaround it. See the method below.
Steps to reproduce:
Try to calculate text width of any unicode word and draw line above printed text.
Additional information:
//workaround function
function TPostScriptPrinterCanvas.TextExtent(const Text: string): TSize;
function aMappedFontName: string;
begin
Result:='Helvetica';
if Copy(LowerCase(Font.Name),1,5)='times' then
Result:='Times';
if (LowerCase(Font.Name)='monospaced') or (Copy(LowerCase(Font.Name),1,7)='courier') then
Result:='Courier';
if LowerCase(Font.Name)='serif' then
Result:='Times';
if LowerCase(Font.Name)='sansserif' then
Result:='Helvetica';
if LowerCase(Font.Name)='symbol' then
Result:='Symbol';
end;
Var IndexFont,i : Integer;
FontName : string;
c: Char;
fTempBuff:TBitmap;
begin
Result.cX := 0;
Result.cY := 0;
if Text='' then Exit;
RequiredState([csHandleValid, csFontValid]);
fTempBuff:=TBitmap.Create;
fTempBuff.Canvas.Font.Assign(Font);
fTempBuff.Canvas.Font.Name:=aMappedFontName;
Result:=fTempBuff.Canvas.TextExtent(Text);
Result.cx:=Round(Result.cx*XDPI/ScreenInfo.PixelsPerInchX);
Result.cy:=Round(Result.cy*YDPI/ScreenInfo.PixelsPerInchY);
fTempBuff.Free;
end;
Mantis conversion info:
- Mantis ID: 15729
- OS: Linux
- OS Build: 2.6.xx
- Platform: Any
- Version: 0.9.28.2
- Monitored by: » Morganhold (Vanya Batalin)