🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #4440

Re: Problem about Text Metrics (tmInternalLeading)

#4440
From: Eyyub Volkan �ektimur
Date: Tue, 24 Jan 2006 15:07
122 lines
5557 bytes
here is some code (my real code is a bit different, i simplified it) ;

----------------------------------------------------------------------------
-----
 TCanvas            *Canvas=Im->Picture->Bitmap->Canvas;    // Canvas
 int                W=Im->Width,H=Im->Height;               // W:Width of
Canvas , H:Height of Canvas
 int                TextWidth;                              // Width of Text
 TPoint             Org(200,200);                           // origin
 AnsiString         Text="Bg��j{}";                         // Text
 double             RotMatrix[4]={1,0,0,1};                 // Rotation
Matrix
 double             RotAngle=0;                             // Rotation
Angle
 OUTLINETEXTMETRIC  md;                                     // text metrics
 TPointd            BoundingPoints[4];                      // bounding
rect./polygon points
 TPointd            P;                                      // temp. point

 // Clear Screen
 Canvas->Pen->Color=clWhite;
 Canvas->Brush->Color=clWhite;
 Canvas->Brush->Style=bsSolid;
 Canvas->FillRect(TRect(0,0,W,H));
 Canvas->Brush->Style=bsClear;

 // Set Font
 Canvas->Font->Name="Arial";
 Canvas->Font->Size=50;
 Canvas->Font->Color=clBlack;
 SetTextAlign(Canvas->Handle,TA_TOP);

 // Set Rotation
 if (RotAngle!=0)
    {
    TLogFont    lf;
    double      Radyan;

    GetObject(Canvas->Font->Handle,sizeof(lf),&lf);
    lf.lfOrientation=RotAngle*10;
    lf.lfOrientation=lf.lfOrientation%(360*10);
    lf.lfEscapement=lf.lfOrientation;
    lf.lfQuality=PROOF_QUALITY;
    lf.lfOutPrecision=OUT_DEVICE_PRECIS;
    Canvas->Font->Handle=CreateFontIndirect(&lf);

    // Prepare Rotation Matrix
    Radyan=M_PI*RotAngle/180;
    RotMatrix[0]=cos(Radyan); RotMatrix[1]=sin(Radyan);
    RotMatrix[2]=-sin(Radyan); RotMatrix[3]=cos(Radyan);
    }

 // Query Font Metrics
 GetOutlineTextMetrics(Canvas->Handle,sizeof(md),&md);
 TextWidth=Canvas->TextWidth(Text);

 // Calculate Bounding Box
 BoundingPoints[0].Set(0,0);
 BoundingPoints[1].Set(TextWidth,0);

BoundingPoints[2].Set(TextWidth,md.otmTextMetrics.tmAscent+md.otmTextMetrics
.tmDescent);

BoundingPoints[3].Set(0,md.otmTextMetrics.tmAscent+md.otmTextMetrics.tmDesce
nt);

 // Apply Rotation Matrix to Points
 for (int cx=0;cx<4;cx++)
     {
     P=BoundingPoints[cx];
     BoundingPoints[cx].x=RotMatrix[0]*P.x+RotMatrix[1]*P.y;
     BoundingPoints[cx].y=RotMatrix[2]*P.x+RotMatrix[3]*P.y;
     }

 // Write Text
 Canvas->TextOut(Org.x,Org.y,Text);

 // Draw Boundary
 Canvas->Pen->Color=clRed;
 Canvas->MoveTo(Org.x+BoundingPoints[0].x,Org.y+BoundingPoints[0].y);
 Canvas->LineTo(Org.x+BoundingPoints[1].x,Org.y+BoundingPoints[1].y);
 Canvas->LineTo(Org.x+BoundingPoints[2].x,Org.y+BoundingPoints[2].y);
 Canvas->LineTo(Org.x+BoundingPoints[3].x,Org.y+BoundingPoints[3].y);
 Canvas->LineTo(Org.x+BoundingPoints[0].x,Org.y+BoundingPoints[0].y);

----------------------------------------------------------------------------
-----

if you set "RotAngle" var. to rotation value (for exm. 45) , you'll see the
rotated Bounding Box. this is how i'm calculating bounding box. it's getting
growed after rotation. and that is my real problem. i want consistent
bounding box. thx for help...
________________________________________
Eyyub Volkan �ektimur
Proya Software & Trade Inc.
Head of Core Development Department
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message
news:851at1p99do8ies9ecclhq8augl9t26cnh@4ax.com...
> Eyyub Volkan �ektimur wrote:
>
> >i didn't used GetTextExtentPoint32. i used GetTextMetrics api to get text
> >metrics. and calculated text boundary with
> >tmAscent,tmInternalLeading,tmDescent values. Isn't GetOutlineTextMetrics
> >returns the same values with GetTextMetrics ? (except more info)
>
> For the 45 degree text, the question still remains if your code
> correctly does the box drawing Trigonometry the same way that MS does
> it.
> That's why I asked to see the code. Something I can compile and play
> with to try to figure it out.
>
> >so, how can i get NEWTEXTMETRIC data ? i couldn't find a realated api
> >method...
>
> It is used in the callbacks to the EnumFont... group of functions.
> See the help page "Enumerating the Installed Fonts"
>
> I am also guessing that if you use it in a call to GetTextMetrics on a
> TrueType font, that the extra members will be filled in, but that's
> just a guess, and could be wrong.
>
>
Technical Details
Message-ID: <43d641c4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43d0b85b$1@newsgroups.borland.com> <kr72t1lqf9lrur0iar1ob0kh4ftr56fn41@4ax.com> <43d49f33$1@newsgroups.borland.com> <851at1p99do8ies9ecclhq8augl9t26cnh@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4faceab9e12cf298
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII
From: "Eyyub Volkan �ektimur" <evcektimur@prokon.com.tr>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <43d0b85b$1@newsgroups.borland.com> <kr72t1lqf9lrur0iar1ob0kh4ftr56fn41@4ax.com> <43d49f33$1@newsgroups.borland.com> <851at1p99do8ies9ecclhq8augl9t26cnh@4ax.com>
Subject: Re: Problem about Text Metrics (tmInternalLeading)
Date: Tue, 24 Jan 2006 17:07:59 +0200
Lines: 124
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 85.100.115.217
Message-ID: <43d641c4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1138115012 85.100.115.217 (24 Jan 2006 07:03:32 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail