?
Solved

Font Points to Pixel.

Posted on 1998-08-24
8
Medium Priority
?
776 Views
Last Modified: 2013-12-02
I'm doing a programm that's pset fonts on a bmp picture, but i want the size of the font to be maybe 20 pixels not 20 points, how do i do ??????
0
Comment
Question by:e_norrman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 200 total points
ID: 1430681
The answer is almost impossible.  The reason being is that the point to pixel ratio will change depending on the resolution, the size of font, the type of font (fixed width or variable width) and the weight of the font.  
For example, Ariel 10pt on a resolution of 1152x864 will have a height of 10 pixels (13 if you include decenders).  A "W" is 13 pixels wide, an "I" is 1 pixel wide.  Changing to Times New Roman Bold 10pt height = 9 pixels (12 with decenders).  A "W" is 13 pixels wide, an I is 4 pixels wide.

The best you can do is try several fonts, cout the pixels and do some calculations.  The results will never be the same for all fonts, though.
0
 

Author Comment

by:e_norrman
ID: 1430682
wondering how they do in paintprogramms like photoshop, when they converting the font to pixels?
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1430683
A quick and dirty way of calculating might be:
Set the font in a picturebox.
To get the values in pixels:
FontWidth = Picture1.TextWidth("X") / Screen.TwipsPerPixelX
FontHeight = Picture1.TextHeight("X") / Screen.TwipsPerPixelY
Remember that these values will change depending on the font used and the resolution of the screen.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:e_norrman
ID: 1430684
solution so far


Dim pix, size As Integer
Dim poi As Double


pix = Screen.TwipsPerPixelY
size= pix * fontstorlek
poi = twi / 27  'or somethimh like that


Picture2.FontSize = poi
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1430685
I'm sorry, but I'm not following your code well.  Can you explain further?
0
 

Author Comment

by:e_norrman
ID: 1430686
dim pix, twi as integer
dim poi as double

1. take out the pixels, twips on the screenY
 then i got that maybe there are xxx twips on 1 pixel

2. then take the twipsperpixel * fontsize
 
3. then the points = the poi/ 23 something realy dont know try and find a number that fit.



pix = Screen.TwipsPerPixelY
twi = pix * fontstorlek
poi = twi / 23
   
fontsize = poi

??????

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1430687
OK, I've been doing some research and there is an API call which will return information on the current font:
Private Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" (ByVal hdc As Long, lpMetrics As TEXTMETRIC) As Long

Private Type TEXTMETRIC
        tmHeight As Long           'Height of font
        tmAscent As Long
        tmDescent As Long
        tmInternalLeading As Long
        tmExternalLeading As Long
        tmAveCharWidth As Long     'Average width of font
        tmMaxCharWidth As Long     'Maximum width of font
        tmWeight As Long           'Boldness
        tmOverhang As Long
        tmDigitizedAspectX As Long
        tmDigitizedAspectY As Long
        tmFirstChar As Byte
        tmLastChar As Byte
        tmDefaultChar As Byte
        tmBreakChar As Byte
        tmItalic As Byte
        tmUnderlined As Byte
        tmStruckOut As Byte
        tmPitchAndFamily As Byte
        tmCharSet As Byte
End Type

Usage:
Private Sub Command1_Click()
  Dim TM As TEXTMETRIC
  Dim lRes As Long
 
  lRes = GetTextMetrics(Form1.hdc, TM)
  Debug.Print TM.tmHeight, TM.tmAveCharWidth
End Sub

0
 

Author Comment

by:e_norrman
ID: 1430688
ok i'll try it out and see what happens  

thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

766 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