From text to PDF (php-pdf), excel macro needs to measure glyph weights

Err

Active Member
Joined
Nov 16, 2006
Messages
274
Hi,

I'm writing a short macro that rewrites a text file to put part of it into a pdf.

The problem that I'm having (besides possibly, using the wrong tool) is that the widths of individual characters change depending on the character. So it is not sufficient to merely count the length of a string because a capital o "O" is so much wider than a lowercase i "i".

I was wondering if anyone has a function that can give different weights for characters.

I started one myself; but while I'm writing it -I'd thought that someone else might have already invented it.

Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I've got this function which I eyeballed to put the width of characters into 3 categories.

Code:
Public Function char_weight(ByVal string_To_eval As String) As Integer

    Dim myChar As String
    Dim myCharNum As Integer
    
    myChar = Left(string_To_eval, 1)
    
    myCharNum = Asc(myChar)
    
    Select Case myCharNum
       Case 32, 33, 39, 44, 46, 49, 58, 59, 96, 105, 108, 124, 127, 129, 130, _
            141, 143, 144, 145, 146, 157, 160, 161, 166, 170, 173, 180, 183, 184, _
            185, 186, 236, 237, 238, 239
            

            char_weight = 1

        Case 34, 40, 41, 42, 47, 48 To 57, 63, 91 To 94, 97 To 104, 106, 107, _
            110 To 118, 120 To 123, 125, 131, 132, 134 To 136, 139, 147 To 150, _
            152, 154, 155, 158, 162 To 164, 167 To 169, 171, 172, 176, 178, 179, _
            181, 182, 187, 191, 215, 224 To 229, 231 To 255


            char_weight = 2



          Case Else
                char_weight = 3
        End Select
        
    
    
End Function
 
Upvote 0
Code:
Public Function char_weight(ByVal string_To_eval As String) As Integer

    Dim myChar As String
    Dim myCharNum As Integer
    
    myChar = Left(string_To_eval, 1)
    
    myCharNum = Asc(myChar)
    
    Select Case myCharNum
       Case 32, 33, 39, 44, 46, 49, 58, 59, 96, 105, 108, 124, 127, 129, 130, _
            141, 143, 144, 145, 146, 157, 160, 161, 166, 170, 173, 180, 183, 184, _
            185, 186, 236, 237, 238, 239
            

            char_weight = 30

        Case 34, 40, 41, 42, 47, 48 To 57, 63, 91 To 94, 97 To 104, 106, 107, _
            110 To 118, 120 To 123, 125, 131, 132, 134 To 136, 139, 147 To 150, _
            152, 154, 155, 158, 162 To 164, 167 To 169, 171, 172, 176, 178, 179, _
            181, 182, 187, 191, 215, 224 To 229, 231 To 255


            char_weight = 56



          Case Else
                char_weight = 80
        End Select
        
    
    
End Function
edit: reassigned weights based on close photoshop analysis of character glyphs
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,820
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top