Skip to content

Commit c3eebc7

Browse files
authored
Tiny changes on commenting for PostScript text, plus doc update (#4250)
* Marginally improve comments The PostScript text typesetting is black magic and too hard to penetrate for me now. I added some more commets but this is not easy to understand, being all in reverse Polish notation to boot. For now we will simply document that the paragraph mode does not support composite characters. * Update text_common.rst_
1 parent d62ea17 commit c3eebc7

File tree

5 files changed

+46
-41
lines changed

5 files changed

+46
-41
lines changed

doc/rst/source/text_common.rst_

+4-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Optional Arguments
148148
**-M**
149149
Paragraph mode. Files must be multiple segment files. Segments are
150150
separated by a special record whose first character must be *flag*
151-
[Default is **>**]. Starting in the 3rd column, we expect to find
151+
[Default is **>**]. Starting in the 3rd field, we expect to find
152152
information pertaining to the typesetting of a text paragraph (the
153153
remaining lines until next segment header). The information expected
154154
is (*x y* [*font angle justify*] *linespace parwidth parjust*),
@@ -159,8 +159,9 @@ Optional Arguments
159159
which may be **l**\ (eft), **c**\ (enter), **r**\ (ight), or
160160
**j**\ (ustified). The segment header is followed by one or more
161161
lines with paragraph text. Text may contain the escape sequences
162-
discussed above. Separate paragraphs with a blank line. Note that
163-
here, the justification set via **-F+j** applies to the box alignment
162+
discussed above, although composite characters are not supported.
163+
Separate paragraphs with a blank line. Note that here,
164+
the justification set via **-F+j** applies to the box alignment
164165
since the text justification is set by *parjust*.
165166

166167
.. _-N:

src/PSL_label.ps

9 Bytes
Binary file not shown.

src/PSL_prologue.ps

9 Bytes
Binary file not shown.

src/PSL_strings.h

+42-38
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static char *PSL_label_str =
3131
"%- out where labels are placed and setting clip paths etc.\n"
3232
"%-\n"
3333
"%- NOTE: No longer used as replaced by static string in PSL_strings.h.\n"
34-
"%- We keep the file in the repository as it may be simpler to see\n"
34+
"%- We keep the file in the repository as it may be simpler to see and edit\n"
3535
"%- the logic in this file than in the static string.\n"
3636
"%-----------------------------------------------------------------------------\n"
3737
"\n"
@@ -672,33 +672,34 @@ static char *PSL_label_str =
672672
static char *PSL_text_str =
673673
"%-----------------------------------------------------------------------------\n"
674674
"%- P. Wessel, version 1\n"
675-
"%- Text justification for paragraphs.\n"
676-
"%- Kept as separate file until stable.\n"
675+
"%- Text justification for paragraphs. Invented via PostScript docs a long time ago.\n"
676+
"%- Kept as separate file because it is easier to edit and see the logic here.\n"
677677
"%- Knows about flush l,c,r and justified.\n"
678-
"%- Knows about all GMT @ escapes, composites,\n"
678+
"%- Knows about all GMT @ escapes, composites (but not in paragraph mode)\n"
679679
"%- and underlining. No hyphenation. 1 page only.\n"
680-
"%- NOTE: No longer used as replaced by static string in PSL_strings.h.\n"
681-
"%- We keep the file in the repository as it may be simpler to see\n"
680+
"%- NOTE: No longer used as is, as replaced by static string in PSL_strings.h.\n"
681+
"%- We keep the file in the repository as it may be simpler to edit and see\n"
682682
"%- the logic in this file than in the static string.\n"
683683
"%-----------------------------------------------------------------------------\n"
684684
"\n"
685-
"/PSL_setfont { % Set Font, size, and color if needed\n"
685+
"/PSL_setfont { % Set Font, size, and color (if needed)\n"
686+
" % Expects two arguments: Word flag and word index\n"
686687
" /f exch def % Gets word flag from stack\n"
687688
" /k1 exch def % Gets word index from stack\n"
688689
" /fz PSL_size k1 get def % Get font size\n"
689-
" /fn PSL_fnt k1 get def % Get font\n"
690-
" fn PSL_lastfn eq fz PSL_lastfz eq and not {\n"
690+
" /fn PSL_fnt k1 get def % Get font number\n"
691+
" fn PSL_lastfn eq fz PSL_lastfz eq and not { % If fonts or sizes differ we must update\n"
691692
" fz PSL_fontname fn get Y % Set font and size\n"
692693
" /PSL_lastfn fn def\n"
693694
" /PSL_lastfz fz def\n"
694695
" } if\n"
695-
" /fc PSL_color k1 get def\n"
696-
" fc PSL_lastfc ne {\n"
696+
" /fc PSL_color k1 get def % Get color\n"
697+
" fc PSL_lastfc ne { % Not the same, must update color\n"
697698
" /PSL_c fc 3 mul def\n"
698699
" 0 1 2 {PSL_c add PSL_rgb exch get} for C % Get and set color\n"
699700
" /PSL_lastfc fc def\n"
700701
" } if\n"
701-
" f 32 and 32 eq { % Underline\n"
702+
" f 32 and 32 eq { % Turn underline on before plotting text\n"
702703
" /PSL_UL fz 0.075 mul def\n"
703704
" fz 0.025 mul W\n"
704705
" /PSL_show {PSL_ushow} def\n"
@@ -709,24 +710,25 @@ static char *PSL_text_str =
709710
"}!\n"
710711
"\n"
711712
"/PSL_setfont2 { % Only set font and size\n"
713+
" % Expects two arguments: Word flag and word index\n"
712714
" /f exch def % Gets word flag from stack\n"
713715
" /k1 exch def % Gets word index from stack\n"
714716
" /fz PSL_size k1 get def % Get font size\n"
715-
" /fn PSL_fnt k1 get def % Get font\n"
717+
" /fn PSL_fnt k1 get def % Get font number\n"
716718
" fn PSL_lastfn eq fz PSL_lastfz eq and not {\n"
717719
" fz PSL_fontname fn get Y % Set font and size\n"
718720
" /PSL_lastfn fn def\n"
719721
" /PSL_lastfz fz def\n"
720722
" } if\n"
721723
"}!\n"
722724
"\n"
723-
"/PSL_wordheight { % Gets word from stack, and calculates any adjustment to box height\n"
725+
"/PSL_wordheight { % Gets word from stack, then calculates any adjustment to box height\n"
724726
" 0 0 M false charpath flattenpath pathbbox /up exch def pop /down exch def pop newpath\n"
725727
" down PSL_ymin lt {/PSL_ymin down def} if\n"
726728
" up PSL_ymax gt {/PSL_ymax up def} if\n"
727729
"}!\n"
728730
"\n"
729-
"/PSL_ushow {\n"
731+
"/PSL_ushow { % Related to underline showing text\n"
730732
" currentpoint /y0 exch def /x0 exch def\n"
731733
" ashow\n"
732734
" currentpoint pop /x1 exch def\n"
@@ -737,24 +739,25 @@ static char *PSL_text_str =
737739
"% Set font, size, and color. Adjust baseline if needed. Place space and word\n"
738740
"\n"
739741
"/PSL_placeword {\n"
740-
" /k exch def % Gets word index from stack\n"
742+
" % Expects one argument: the word index from stack\n"
743+
" /k exch def % Gets word index\n"
741744
" /flag PSL_flag k get def\n"
742745
" k flag PSL_setfont\n"
743746
" /sshow {ashow} def\n"
744-
" PSL_col 0 eq { % First word on a line\n"
747+
" PSL_col 0 eq { % First word on a new line\n"
745748
" /PSL_t 0 def % 0 spaces before this word\n"
746-
" flag 4 and 4 eq { % Must skip one TAB\n"
749+
" flag 4 and 4 eq { % Flag says we must skip one TAB (here 4 spaces)\n"
747750
" pr_char 0 ( ) ashow\n"
748751
" } if\n"
749752
" }\n"
750-
" { % Need to find spaces before this word\n"
751-
" /f PSL_flag k 1 sub get def % f is flag for previous word\n"
753+
" { % Need to find spaces before this word\n"
754+
" /f PSL_flag k 1 sub get def % f is the flag for previous word\n"
752755
" /PSL_t f 3 and def % PSL_t is index into PSL_spaces and PSL_spacewidths for previous word\n"
753756
" f 32 and 32 eq flag 32 and 32 eq and {/sshow {PSL_ushow} def} if\n"
754757
" } ifelse\n"
755758
" /thisword_bshift PSL_bshift k get def % The baseline shift\n"
756759
" thisword_bshift 0.0 ne {0 thisword_bshift G} if % Shift baseline\n"
757-
" flag 8 and 8 eq { % First composite char\n"
760+
" flag 8 and 8 eq { % First composite char (flagged with 8)\n"
758761
" pr_char 0 PSL_spaces PSL_t get sshow\n"
759762
" k PSL_composite\n"
760763
" } if\n"
@@ -766,18 +769,19 @@ static char *PSL_text_str =
766769
"}!\n"
767770
"\n"
768771
"/PSL_composite { % Place a composite character\n"
772+
" % Expects a word index from the stack\n"
769773
" /k1 exch def % Get word index from stack\n"
770-
" /k2 k1 1 add def\n"
771-
" /char1 PSL_word k1 get def\n"
772-
" /char2 PSL_word k2 get def\n"
773-
" /flag2 PSL_flag k2 get def\n"
774-
" /w1 char1 stringwidth pop def\n"
775-
" flag2 64 and 64 eq { % We have a font change before the 2nd composite character\n"
774+
" /k2 k1 1 add def % Index to the 2nd composite character\n"
775+
" /char1 PSL_word k1 get def % First character\n"
776+
" /char2 PSL_word k2 get def % Second character\n"
777+
" /flag2 PSL_flag k2 get def % Second character flag\n"
778+
" /w1 char1 stringwidth pop def % Width of first character\n"
779+
" flag2 64 and 64 eq { % Here, 64 means we have a font change before the 2nd composite character\n"
776780
" /fn2 PSL_fnt k2 get def % Get the other font array number\n"
777781
" fz PSL_fontname fn2 get Y % Set font and size for the 2nd composite character\n"
778782
" } if\n"
779-
" /w2 char2 stringwidth pop def\n"
780-
" /delta w1 w2 sub 2 div PSL_scale mul def\n"
783+
" /w2 char2 stringwidth pop def % Width of second character\n"
784+
" /delta w1 w2 sub 2 div PSL_scale mul def % Adjust and center based on w1, w2\n"
781785
" delta 0.0 gt {\n"
782786
" /dx1 0 def\n"
783787
" /dx2 delta def\n"
@@ -787,7 +791,7 @@ static char *PSL_text_str =
787791
" /dx2 0 def\n"
788792
" } ifelse\n"
789793
" dx1 0 G currentpoint\n"
790-
" flag2 64 and 64 eq { % Must switch back to 1st composite character font and set it\n"
794+
" flag2 64 and 64 eq { % Must switch back to first composite character font and set it\n"
791795
" /fn1 PSL_fnt k1 get def % Get initial font\n"
792796
" fz PSL_fontname fn1 get Y % Set font and size\n"
793797
" } if\n"
@@ -815,7 +819,7 @@ static char *PSL_text_str =
815819
" /PSL_col 0 def\n"
816820
"}!\n"
817821
"\n"
818-
"% Calculate text paragraph height:\n"
822+
"% Calculate text paragraph height or place it:\n"
819823
"\n"
820824
"/PSL_textjustifier {\n"
821825
" /PSL_mode exch def % From stack. 0 -> calculate height, no text is placed, 1 -> place text\n"
@@ -836,14 +840,14 @@ static char *PSL_text_str =
836840
" /line 0 def\n"
837841
" /ncomp 0 def\n"
838842
" /comp_width 0 def\n"
839-
" 0 1 PSL_n1 { % Loop over all the words\n"
843+
" 0 1 PSL_n1 { % Loop over all the words in the array\n"
840844
" /i exch def % The current loop index\n"
841-
" /thisflag PSL_flag i get def % # of space chars to follow this word\n"
842-
" i 0 eq {\n"
845+
" /thisflag PSL_flag i get def % Number of space chars to follow this word\n"
846+
" i 0 eq { % At the first word\n"
843847
" /PSL_t 0 def\n"
844848
" /lastflag 0 def\n"
845849
" }\n"
846-
" { /lastflag PSL_flag i 1 sub get def\n"
850+
" { /lastflag PSL_flag i 1 sub get def % Can get the previous flag\n"
847851
" /PSL_t lastflag 3 and def\n"
848852
" } ifelse\n"
849853
" % PSL_t is index into PSL_spaces and PSL_spacewidths\n"
@@ -877,9 +881,9 @@ static char *PSL_text_str =
877881
" }\n"
878882
" { % Must process current line and move to next\n"
879883
" 1 PSL_mode eq { % Write out the first word on this line\n"
880-
" % Determine how much to expand text and also justify left/center/right\n"
884+
" % Determine how much to expand text and also justify left/center/right\n"
881885
" start PSL_expand\n"
882-
" start PSL_placeword\n"
886+
" start PSL_placeword\n"
883887
" }\n"
884888
" {PSL_word start get PSL_wordheight\n"
885889
" } ifelse\n"
@@ -932,7 +936,7 @@ static char *PSL_text_str =
932936
static char *PSL_prologue_str =
933937
"%-----------------------------------------------------------------------------\n"
934938
"%- NOTE: No longer used as replaced by static string in PSL_strings.h.\n"
935-
"%- We keep the file in the repository as it may be simpler to see\n"
939+
"%- We keep the file in the repository as it may be simpler to see and edit\n"
936940
"%- the logic in this file than in the static string.\n"
937941
"%-----------------------------------------------------------------------------\n"
938942
"% Begin pslib header\n"

src/PSL_text.ps

840 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)