Hello fellow monks. I am trying to build a custom PCL downloadable soft font. This is a series of PCL commands which describe how to render each ASCII character in a font set, which can be transferred to modern LaserJet compatible printers and augment their built-in font capabilities. The PCL involved is very tightly packed, to the point where several font characteristics are combined into 2 bytes. For example, the "posture" (upright, italic, etc) and the "structure" (solid, outline, shadow, etc) are combined across 2 bytes. Here is a short diagram:
| Style MSB | Style LSB | |15 9 | 4 1 0| ----------------------------------------- | reserved |Structure|App wid|Pos| So, reading from right to left, bits 0 and 1 = Posture (poss values 0-3) bits 2-4 = Appearance Width (0-7) bits 5-9 = Structure (0-31) bits 10-15 = Reserved (locked to value of 0)
Well, I understand binary math and what I *want* the final 16 bit thingy to look like. I'm still fuzzzy on how to use pack() to achieve this. If, for example:
posture=2 (10) app_width=5 (101) structure=6 (00110) then the bits should look like: 000000 00110 101 10 or, without the spaces: 0000000011010110
I've tried
my $style_word=pack(b2 b3 b5 b6),$pos,$aw,$stru,0;
but that doesn't work. Should I be using b or B as a template code? Should I be using regular integer values like 2, 5 and 6 or should I be packing those into some other bitstring first? Worse yet, I'm at a loss on how to debug this thing and see an understandable representation of what's really getting put into $sw. I'd love to see a series of 0's and 1's which represent the individual bits of this 16 bit word. Then I could be sure what I'm putting into the structure before writing it to disk. Any help would be greatly appreciated.

Shelob

When there is no wind, row.

In reply to using pack() to build a 16 bit word by shelob101

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.