🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problem about Text Metrics (tmInternalLeading)

#4443
From: Bob Gonder
Date: Wed, 25 Jan 2006 01:36
82 lines
3676 bytes
Ok, here's what I found.
MS fudges the text height when rotated.
The rotated text height on screen is actually the same as non-rotated.
So get the non-rotated height, and adjust the box.
This is complicated by you using TA_TOP because you need to adjust the
start location of the box. If you used TA_BOTTOM, you'd just need to
use the correct height I think (and change the box calc for negative
Y).
This isn't perfect, but seems to be pretty close, at least at normal
font sizes. Change Dy,Dx to 50,50, and it's off.

	POINT	BoundingPoints[5] = {0};
	POINT	P;

	HFONT	Font = CreateFont(
		0,0,//Dy,Dx,
		RotAngle*10,		// angle of escapement
		RotAngle*10,		// base-line orientation angle
		FW_NORMAL,		// font weight
		FALSE,			// italic attribute flag
		FALSE,			// underline attribute flag
		FALSE,			// strikeout attribute flag
		DEFAULT_CHARSET,	// character set identifier
		OUT_DEVICE_PRECIS,	// output precision
		CLIP_DEFAULT_PRECIS,	// clipping precision
		PROOF_QUALITY,		// output quality
		VARIABLE_PITCH+FF_DONTCARE,	// pitch and family
		"Arial"			// typeface name string
	);
	SelectObject(hdc,(HGDIOBJ)Font);
	SetTextAlign( hdc, TA_TOP );
	SetBkMode( hdc, OPAQUE ); /* shows full size of text field */
	TextOut( hdc, Org.x, Org.y, Text, lstrlen(Text) );

	SIZE	lpSize;
	GetTextExtentPoint32( hdc, Text, lstrlen(Text), &lpSize );
	TextWidth = lpSize.cx;

	GetTextMetrics( hdc, &tm );

	switch( type )
	{case 0:	// non-rotated
		TextHeight = lpSize.cy;
		OldTextHeight = TextHeight;
		OldAscent = tm.tmAscent;
		break;
	case 2:	// 135 degrees
		TextHeight = OldTextHeight;
		Org.x += (tm.tmAscent - OldAscent);
		Org.y -= (tm.tmAscent - OldAscent);
		break;
	case 1:	// 45 degrees
		TextHeight = OldTextHeight;
		Org.x += (tm.tmAscent - OldAscent);
		Org.y += (tm.tmAscent - OldAscent);
		break;
	case other:
		write the code for 225 and 315
	};

	BoundingPoints[1].x = TextWidth;
	BoundingPoints[2].x = TextWidth;
	BoundingPoints[2].y = TextHeight;
	BoundingPoints[3].y = TextHeight;

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

	// Draw Boundary
	Polyline( hdc, BoundingPoints, 5 );


Entire test code available if you need it.
Technical Details
Message-ID: <jijdt1du2lvrtfp5rd0m79m4qkn0d37far@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!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> <43d641c4$1@newsgroups.borland.com> <8a1dt19a0kbk35sqtoq6sqdl5a2hn68u9i@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4faceab9e12cf298
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Problem about Text Metrics (tmInternalLeading)
Date: Tue, 24 Jan 2006 17:36:25 -0800
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <jijdt1du2lvrtfp5rd0m79m4qkn0d37far@4ax.com>
References: <43d0b85b$1@newsgroups.borland.com> <kr72t1lqf9lrur0iar1ob0kh4ftr56fn41@4ax.com> <43d49f33$1@newsgroups.borland.com> <851at1p99do8ies9ecclhq8augl9t26cnh@4ax.com> <43d641c4$1@newsgroups.borland.com> <8a1dt19a0kbk35sqtoq6sqdl5a2hn68u9i@4ax.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 71.0.35.226
X-Trace: newsgroups.borland.com 1138152805 71.0.35.226 (24 Jan 2006 17:33:25 -0700)
Lines: 85
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail