smarthaert / phoenixlib

Automatically exported from code.google.com/p/phoenixlib
0 stars 0 forks source link

Text Align Center is "one character" to the right #80

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Text Align Center seens to be "1 character" to the right than the real center!

Original issue reported on code.google.com by wagenhei...@gmail.com on 23 Sep 2010 at 2:37

GoogleCodeExporter commented 9 years ago
The bug is with TextWidth Function, that is returning the wrong size (Try to 
draw a FrameRect in the font, and you will see that the framerect is smaller 
than the Font).

Parcial fix for this is :

function TPHXFont.TextExtent(const Text: AnsiString): TVector2i;
var Index    : Cardinal;
var Character: Integer;
var LineWidth: Integer;
begin
  // No text
  if Length(Text) = 0 then
  begin
    Result.X:= 0;
    Result.Y:= 0;

    Exit;
  end;

  // Get the first character
  Character:= CharacterMap[ Ord( Text[1] ) ];
  // Compensate for the offset of the first character
  Result.X:= FCharacters.List^[Character].Width -    FCharacters.List^[Character].XAdvance - FCharacters.List^[Character].XOffset;

  Result.Y:= Metric.Height;

Original comment by wagenhei...@gmail.com on 14 Oct 2010 at 2:58

GoogleCodeExporter commented 9 years ago
  LineWidth:= Result.X;

Original comment by wagenhei...@gmail.com on 14 Oct 2010 at 2:58

GoogleCodeExporter commented 9 years ago

Original comment by andreas....@gmail.com on 21 Oct 2010 at 6:00