Article View: borland.public.delphi.nativeapi
Article #12161Windows Fonts
From: Camiel Wijffels
Date: Fri, 22 Nov 2002 17:02
Date: Fri, 22 Nov 2002 17:02
100 lines
4754 bytes
4754 bytes
Hi
I really need to speak with someone who has really experienced the windows
Fonts........
I'm building an app to design page layout, including text. This text should
be scaled, so what I need is a text-drawing function with scaling ability.
For example, I need to draw the text 'hello', 300 pixels wide. Next time I
would like to draw the same text at 301 pixels wide, or 307, or 312 (these
figures are purely random). It is possible - many professional packages
(like WP, Word and CorelDraw) have this ability.
What I got so far (with Windows.TextOut) is an output text of, for example,
300 pixels wide with 100% scale. When I enter 101% scale the width doesnt
change, also with 102% and 103% the width doesnt change. Only when I enter
104% (for example!) then th width becomes suddenly 314 pixels.
The used code is below, if you're intersted: (there is a minor error in
establishing iFactorX and iFactorY)
-----------------------------------------
function W32TextOut(ACanvas: TCanvas; AFontName: string; ARct: TRect; ASize:
double; AStyles: TFontStyles;
AScale: double; AColor: TColor; AText: string): integer;
var
iLogFont: TLogFont;
iFont: HFont;
iFactorX: double;
iFactorY: double;
iVertSize: integer;
iVertRes: integer;
iLogPixelsY: integer;
iMapMode: integer;
iWidth: integer;
iTextMetric: TTextMetric;
begin
Result := 0;
with ACanvas do begin
iFactorX := (GetDeviceCaps(Handle, HORZSIZE)/GetDeviceCaps(Handle,
HORZRES))*100;
iVertSize := GetDeviceCaps(Handle, VERTSIZE);
iVertRes := GetDeviceCaps(Handle, VERTRES);
iLogPixelsY := GetDeviceCaps(Handle, LOGPIXELSY);
iFactorY := (iVertSize/iVertRes)*100;
with ARct do
ARct := Rect(Trunc(Left*iFactorX), Trunc(-Top*iFactorY),
Trunc(Right*iFactorX), Trunc(-Bottom*iFactorY));
SetGraphicsMode(Handle, GM_COMPATIBLE);
SetBkMode(Handle, TRANSPARENT);
iMapMode := SetMapMode(Handle, MM_HIMETRIC);
try
FillChar(iLogFont, SizeOf(iLogFont), 0);
with iLogFont do begin
StrPCopy(lfFaceName, AFontName);
lfWeight := FW_NORMAL;
if (fsBold in AStyles) then
lfWeight := FW_Bold;
lfHeight := Rounded((ASize*iVertSize*iVertRes)/(iLogPixelsY*100));
lfWidth := 0;
lfEscapement := 0;
lfOrientation := 0;
lfItalic := integer(fsItalic in AStyles);
lfUnderline := integer(fsUnderline in AStyles);
lfStrikeOut := integer(fsStrikeOut in AStyles);
lfOutPrecision := OUT_TT_ONLY_PRECIS;
lfQuality := DRAFT_QUALITY
end;
iFont := CreateFontIndirect(iLogFont);
try
Font.Handle := iFont;
GetTextMetrics(Handle, iTextMetric);
iWidth := Rounded(iTextMetric.tmAveCharWidth*AScale);
finally
DeleteObject(iFont);
end;
iLogFont.lfWidth := iWidth;
iFont := CreateFontIndirect(iLogFont);
try
Font.Handle := iFont;
Result := DrawText(Handle, PChar(AText), Length(AText), ARct, 0);
finally
DeleteObject(iFont);
end;
finally
SetMapMode(Handle, iMapMode);
end;
end;
end;
-----------------------------------------
Met vriendelijke groet, Camiel Wijffels
===============================================
Vertrouwelijk. Dit bericht is uitsluitend bestemd voor de geadresseerde.
Confidential. This message is ment for the addressed recipient only.
===============================================
--
Met vriendelijke groet, Camiel Wijffels
===============================================
Vertrouwelijk. Dit bericht is uitsluitend bestemd voor de geadresseerde.
Confidential. This message is ment for the addressed recipient only.
===============================================
Technical Details
Message-ID:
<3dde62a7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f94dd,cd35213a00f4b682,start X-Google-Attributes: gidf94dd,public X-Google-ArrivalTime: 2002-11-22 09:15:50 PST From: "Camiel Wijffels" <C.Wijffels@BluePrintST.com> Newsgroups: borland.public.delphi.nativeapi Subject: Windows Fonts Date: Fri, 22 Nov 2002 18:02:46 +0100 Lines: 102 Organization: BluePrint X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 195.121.71.196 Message-ID: <3dde62a7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1037984423 195.121.71.196 (22 Nov 2002 09:00:23 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail