Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal nocomment's Journal: calculating chars per inch 6

I cannot seem to find an easy way to calculate chars per inch. Anyone know of a unix utility that does that? I've found a lot that can convert to a set limit (for sending to printers etc...).

This discussion has been archived. No new comments can be posted.

calculating chars per inch

Comments Filter:
  • Other than courier, there are very few monospaced fonts used anymore. So each letter is a different width (e.g. i vs. m) and the exact widths differ from one font to another -- and the relative width (e.g. the ratio of the width of i to the width of m) differs from one font to another.

    Are you looking for something that knows the exact width of each letter for every font you use? How do you want it to calculate characters per inch? Characters per inch would have to be an average. How should this be calculate
    • Other than courier, there are very few monospaced fonts used anymore. So each letter is a different width (e.g. i vs. m) and the exact widths differ from one font to another -- and the relative width (e.g. the ratio of the width of i to the width of m) differs from one font to another.

      Are you looking for something that knows the exact width of each letter for every font you use? How do you want it to calculate characters per inch? Characters per inch would have to be an average. How should this be calcul

      • i don't think wc can do chars, I think it just does bytes, lines, and 'words'. bytes would normally work except symbols are 2 bytes long. So a period throws things off.

        I think I may just write some script to do it, read in the contents of the file, and print the length of the string.
  • Something like this snippet of PostScript will return the width (in inches) of some text:

    /Times-Roman findfont 24 scalefont setfont (This is a test) stringwidth pop 72 div =

    Substitute different fonts, sizes, and text as needed.

    • Yeah I got ghostscript, how do I use that snippet?
      Do I paste it into some ghostscript shell somewhere?
      • by ncc74656 ( 45571 ) *
        You can pipe it in and get the result from stdout:

        echo '/Times-Roman findfont 24 scalefont setfont (This is a test) stringwidth pop 72 div =' | gs -sDEVICE=nullpage -dNOPAUSE -q -

        That'll work within a shell script, at least. Getting it working within a C/C++ program would involve a few more tricks (mainly to capture stdout from another program) that I've not had to puzzle through yet.

Real Programs don't use shared text. Otherwise, how can they use functions for scratch space after they are finished calling them?

Working...