Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I hope this is not too off topic here, since I cannot think of a place with more experts where I could ask. The background is, that I want to improve my ASCII-art algorithm which works fine (about 70k letters here) but I have some other ideas I want to implement:

enter image description here

Beside some details of the algorithm itself, I want to implement the following:

Postscript output

I want to place say 500x500 letters in a way that the line-space is as big as the interletter space and that the font-size is calculated automatically so that this rectangle fits onto some (say A4) paper size. Here is a minimal postscript example I hacked up for testing

%!PS-Adobe-2.0
%%Creator: cpierce1@ford.com
%%EndComments
/Courier findfont 7.7 scalefont setfont
72 500 translate
0 0 moveto
(abcdefhikl) show
0 -5 moveto
(mnorstuvwx) show
0 -10 moveto
(zABCDEFGHI) show
0 -15 moveto
(JKLMNOPRS!) show
0 -20 moveto
(TUVWXYZ.=-) show
0 -25 moveto
showpage
%%Pages: 1

Which produces

enter image description here

Note that I just guessed the font-scaling and the moveto size.

Question: If I only now how many letters nx*ny I have, is it possible to calculate the font-scaling the the moveto size so that the rectangle fits on the paper?

Font brightness calculation

For a really good output, I need to calculate the brightness of the letters as precisely as possible. In the image of the ps-file above, you see that all letters are surrounded by a small white border. This border depends in x-direction on the inter-letter distance and in y-direction on the font-scale/moveto values.

Question: Is it possible to create a high-resolution image (png, tiff, ..) of every letter? Note, for a correct calculation the white border in the images is required to be the same size as if the letter would be surrounded by other letters.

Further notes

I decided not to take letters like "Qyg" which have a sub-length because they are very rare and make the lines be more appart. This makes the calculation of the correct line-space maybe impossible.

I'm always open for other suggestions. I chose the post-script output because I can transform the ascii-text really easy into the (...) show; ... moveto form. And, I have control over the letter scaling and distances. Maybe there is a better/easier way.

share|improve this question
1  
Are the same characters always the same colour/brightness? You can always use a fixed-width font and listings's "literate programming" to manipulate the typesetting of individual characters. The resizing of the output to fit within the margins is also easily possible through an entire scaling of the output. –  Werner Sep 20 '12 at 3:29
    
@Werner Yes, the brightness of a single letter is always the same. If you look from very far on a letter, you don't see the letter, you only see a gray spot. A . is brighter than an X and you can calculate this brightness. Then you replace every pixel in the image with a letters and viewed from very far it looks like the first image in my post. –  halirutan Sep 20 '12 at 8:44

1 Answer 1

What I have below isn't a finished product, but will give you ideas, perhaps on how to proceed. Key features: I use \texttt just to make it quick, but you should invoke your non-proportional font in whatever appropriate fashion. I set \baselineskip to some appropriate number, which will control the vertical interline spacing. Your font width plus the baselineskip will determine the box size being used for each letter of your sketch. Finally, I use the \scaleto program to scale the result to a final desired vertical size, in this case 3". Adjusting those three numbers (font character width [determined by the font used], baselineskip, and scaleto size) should allow you to generate something you desire, I think.

\documentclass[12pt]{article}
\usepackage{courier}
\usepackage{scalerel}
\parindent 0ex
\begin{document}
\scaleto{
  \parbox{2in}{\baselineskip 1.5ex\texttt{%
    abcdefhikl\\
    mnorstuvwx\\
    zABCDEFGHI\\
    JKLMNOPRS!\\
    TUVWXYZ.=-
  }}
}{3in}
\end{document}

p.s. The parbox width is a fourth number to which you need to pay attention. It has to be large enough to contain the unscaled text that you stuff into it (which means it might have to be significantly larger than a pagewidth). But don't worry,; scalerel will bring back to a size worthy of a page.

share|improve this answer
    
Cool. Question off-topic, answer onT. –  Speravir Mar 5 '13 at 3:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.