?
Solved

Drawing glyphs from true type font

Posted on 2004-11-15
6
Medium Priority
?
805 Views
Last Modified: 2013-12-03
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)

thanks!

0
Comment
Question by:bish wakim
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12588951
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.
0
 

Author Comment

by:bish wakim
ID: 12605929

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;
      x:integer;
      rec:trect;
begin
  T := '';
  with Canvas.Font do
  begin
    Name :='times new roman';
    Size := 40;
    color:=clred;
  end;

  t:=widechar($FEA0);
  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: }
  rec:=rect(0,0,canvas.TextWidth(t),canvas.Textheight(t));
  canvas.Brush.Color:=clblue;
  canvas.FrameRect(rec);
end;

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!

0
 
LVL 2

Accepted Solution

by:
sdmason earned 600 total points
ID: 12606214
Since you are using WideChar you need to use the W version  of  the text size functions.  Modifying your code

var
  T                                     : WideString;
  x                                     : integer;
  rec                                   : trect;
  ACanvas : TCanvas;
  szTest : TSize;
begin
  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.FrameRect(rec);

 // 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;
  ACanvas.FrameRect(rec);

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12606253
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;
begin
  ...
  Windows.GetTextExtentPoint32W(Canvas.Handle, PChar(t), Length(t), Size);
  rec:=rect(0,0,Size.cX,Size.cY);
  ...

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...
0
 

Author Comment

by:bish wakim
ID: 12633241
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);
 
thanks!
0
 

Author Comment

by:bish wakim
ID: 12638116
I could fix the problem my self! than you
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question