Drawing glyphs from true type font

Iam Delphi7 user.
When I open a true font type such as times new romans with font creator program , I can see that there are hundreds  of glyphs . each glyph is described by mapping value.
 how can I:
1.  draw a single glyph giving the mapping value (ex: $FEDC) on a canvas ?
2.   get the exact width and the exact height of this glyph?(without spaces)


bish wakimAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wim ten BrinkSelf-employed developerCommented:
You'll need some unicode version of some Windows API to display those values since they're unicode characters. http://unicode.soft-gems.net/ for some information about unicode.
bish wakimAuthor Commented:

I expected a bit more  from an expert  . thank you any way!!
Let me describe my real problem!
the value $FEA0  represents a certain  character in arabic language from  "times new roman"  true type font.
So I could make delphi draw it by the procedure bellow :

procedure TForm1.Button5Click(Sender: TObject);
var T: WideString;
  T := '';
  with Canvas.Font do
    Name :='times new roman';
    Size := 40;

  ExtTextOutW(Canvas.Handle,0,0,ETO_OPAQUE, nil,PWideChar(T),Length(T), nil);

  {draw a blue rectangle to show the limits of this character so: }

the glyph is well drawn but is  not contained into the blue rectangle which indicats that
canvas.textwidth does not give the exact width of character.
what is the problem with canvas.textwidth? is there another function that does the job correctly???

Thank in advance!

Since you are using WideChar you need to use the W version  of  the text size functions.  Modifying your code

  T                                     : WideString;
  x                                     : integer;
  rec                                   : trect;
  ACanvas : TCanvas;
  szTest : TSize;
  ACanvas := pbTest.Canvas;  // Just setting to a paintbox for testing

  T := '';
  ACanvas.Font.Name := 'Times New Roman';
  ACanvas.Font.Size := 40;
  ACanvas.Font.Color := clRed;

  t := widechar($FEA1);
  ExtTextOutW(ACanvas.Handle, 0, 0, ETO_OPAQUE, nil, PWideChar(T), Length(T), nil);

  {draw a blue rectangle to show the limits of this character so: }
  rec := rect(0, 0, ACanvas.TextWidth(t), ACanvas.Textheight(t));
  ACanvas.Brush.Color := clblue;

 // ACanvas.TextWidth calls GetTextExtentPoint and returns the cx portion of a TSize.
  // You can call GetTextExtentPointW directly like you did with ExtTextOutW
  Windows.GetTextExtentPointW(ACanvas.Handle, WideChar($FEA1), 1, szTest);
  rec := rect(0, 0, szTest.cX, szTest.cY);
  ACanvas.Brush.Color := clGreen;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Wim ten BrinkSelf-employed developerCommented:
Here again the ASCII<->Unicode conflict. Delphi uses GetTextExtentPoint internally to get the text characteristics while you will need the GetTextExtentPointW (Unicode) function instead. Something like:

var Size:TSize;
  Windows.GetTextExtentPoint32W(Canvas.Handle, PChar(t), Length(t), Size);

I'm not too familiar with Unicode, though. I don't have to use it in general and know it can be a real pain sometimes...
bish wakimAuthor Commented:
hi sdmason
yes it works ! but  there are still two problems to fix :

1. I would like to pass a parametre instead of  $FEA1 in the line :
   Windows.GetTextExtentPointW(ACanvas.Handle, WideChar($FEA1), 1, szTest);
  I tried to use pwidechar(T) instead of WideChar($FEA1)   but it does not work.

2. have you an idea what changes to do in the line below in order to  draw the character in transparent mode so it does not erase what comes behinde??
 ExtTextOutW(ACanvas.Handle, 0, 0, ETO_OPAQUE, nil, PWideChar(T), Length(T), nil);
bish wakimAuthor Commented:
I could fix the problem my self! than you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.