• How can I define the background color of a character ?

    From wolfgang bauer (D)@21:1/5 to All on Tue Feb 18 18:54:47 2025
    Hi

    I want to write a program, that creates a pdf-file. It works. But I need to define not only the
    foreground-color of characters but also the background color.


    I can change the foreground-color by using the command "rg". Is there a similar command for the background color ?




    --
    Gruß, Greetings

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Herbert Kleebauer@21:1/5 to All on Tue Feb 18 23:43:39 2025
    On 18.02.2025 18:54, wolfgang bauer (D) wrote:

    I want to write a program, that creates a pdf-file. It works. But I need to define not only the
    foreground-color of characters but also the background color.


    I can change the foreground-color by using the command "rg". Is there a similar command for the background color ?

    Draw a box in the background color an then write the text.
    Don't know if the appended pdf file works if you just
    copy&paste it (should be 3565 byte). If not, you can generate
    it with makepdf2.exe form https://www.onlib.de/pub/pdf/makepdf.zip
    and the input file:

    <inittext []>
    {1 1 0 rg 1 0 1 RG 4 w 120 700 m 480 700 l 480 600 l 120 600 l 120 700 l B } [/F6 40 Tf 2 Tr 0 1 1 rg 0 0 0 RG 2 w 1 0 0 1 180 640 Tm] Hello World


    Here the pdf:

    %PDF-1.2
    %123 This is a binary file. Don't edit.
    %created by MakePDF V 0.08 alpha
    %http://www.bitlib.de/pub/pdf/
    8 0 obj
    <<
    /F1 9 0 R
    /F2 10 0 R
    /F3 11 0 R
    /F4 12 0 R
    /F5 13 0 R
    /F6 14 0 R
    /F7 15 0 R
    /F8 16 0 R
    /F9 17 0 R
    /F10 18 0 R
    /F11 19 0 R
    /F12 20 0 R
    /F13 21 0 R
    /F14 22 0 R

    endobj
    9 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F1
    /BaseFont /Courier
    /Encoding /WinAnsiEncoding

    endobj
    10 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F2
    /BaseFont /Courier-Bold
    /Encoding /WinAnsiEncoding

    endobj
    11 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F3
    /BaseFont /Courier-Oblique
    /Encoding /WinAnsiEncoding

    endobj
    12 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F4
    /BaseFont /Courier-BoldOblique
    /Encoding /WinAnsiEncoding

    endobj
    13 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F5
    /BaseFont /Helvetica
    /Encoding /WinAnsiEncoding

    endobj
    14 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F6
    /BaseFont /Helvetica-Bold
    /Encoding /WinAnsiEncoding

    endobj
    15 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F7
    /BaseFont /Helvetica-Oblique
    /Encoding /WinAnsiEncoding

    endobj
    16 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F8
    /BaseFont /Helvetica-BoldOblique
    /Encoding /WinAnsiEncoding

    endobj
    17 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F9
    /BaseFont /Symbol

    endobj
    18 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F10
    /BaseFont /Times-Roman
    /Encoding /WinAnsiEncoding

    endobj
    19 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F11
    /BaseFont /Times-Bold
    /Encoding /WinAnsiEncoding

    endobj
    20 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F12
    /BaseFont /Times-Italic
    /Encoding /WinAnsiEncoding

    endobj
    21 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F13
    /BaseFont /Times-BoldItalic
    /Encoding /WinAnsiEncoding

    endobj
    22 0 obj
    <<
    /Type /Font
    /Subtype /Type1
    /Name /F14
    /BaseFont /ZapfDingbats

    endobj
    24 0 obj
    << /Length 25 0 R >>
    stream
    1 1 0 rg 1 0 1 RG 4 w 120 700 m 480 700 l 480 600 l 120 600 l 120 700 l B
    BT
    /F6 40 Tf 2 Tr 0 1 1 rg 0 0 0 RG 2 w 1 0 0 1 180 640 Tm
    (Hello World) Tj T*
    T*
    ET
    endstream
    endobj
    25 0 obj
    167
    endobj
    26 0 obj
    <<
    /Type /Page
    /Parent 23 0 R
    /Resources 27 0 R
    /MediaBox [0 0 595 842]
    /Contents 24 0 R

    endobj
    27 0 obj
    <<
    /Font 8 0 R
    /ProcSet 6 0 R

    endobj
    1 0 obj
    <<
    /Type /Catalog
    /Outlines 2 0 R
    /Pages 3 0 R
    /OpenAction 4 0 R
    /ViewerPreferences 5 0 R

    endobj
    2 0 obj
    <<
    /Type /Outlines
    /Count 0

    endobj
    3 0 obj
    <<
    /Type /Pages
    /Count 1
    /Kids [23 0 R ]

    endobj
    23 0 obj
    <<
    /Type /Pages
    /Parent 3 0 R
    /Count 1
    /Kids [26 0 R ]

    endobj
    4 0 obj
    <<
    /Type /Action
    /S /GoTo
    /D [26 0 R /Fit]

    endobj
    5 0 obj
    <<
    /PageLayout /OneColumn

    endobj
    6 0 obj
    [/PDF /Text /ImageC]
    endobj
    7 0 obj
    <<
    /Producer (MakePDF V0.08 alpha 08.09.11)

    endobj
    xref
    0 28
    0000000000 65535 f
    0000002376 00000 n
    0000002493 00000 n
    0000002545 00000 n
    0000002693 00000 n
    0000002761 00000 n
    0000002810 00000 n
    0000002849 00000 n
    0000000117 00000 n
    0000000314 00000 n
    0000000428 00000 n
    0000000548 00000 n
    0000000671 00000 n
    0000000798 00000 n
    0000000915 00000 n
    0000001037 00000 n
    0000001162 00000 n
    0000001291 00000 n
    0000001377 00000 n
    0000001497 00000 n
    0000001616 00000 n
    0000001737 00000 n
    0000001862 00000 n
    0000002611 00000 n
    0000001955 00000 n
    0000002181 00000 n
    0000002204 00000 n
    0000002321 00000 n
    trailer
    <<
    /Size 28
    /Root 1 0 R
    /Info 7 0 R

    startxref
    2916
    %%EOF

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From wolfgang bauer (D)@21:1/5 to All on Wed Feb 19 00:53:34 2025
    18.02.25 , 23:43 , Herbert Kleebauer:

    On 18.02.2025 18:54, wolfgang bauer (D) wrote:

    I want to write a program, that creates a pdf-file. It works. But I need to define not only the
    foreground-color of characters but also the background color.


    I can change the foreground-color by using the command "rg". Is there a similar command for the background color ?

    Draw a box in the background color an then write the text.
    Don't know if the appended pdf file works if you just


    It works. Thank you for the answer. But it is not exactly, what I meant. I want to define the background color
    of every single character. I can try, what you suggested, to draw an rectangle in the wanted color and
    write then the character over it. But I would prefer a simpler solution. And my problem is: How
    can I calculate in realtime the dimensions of that rectangle ? I don't want to have to determine the
    values by experimenting. I'm currently doing this as an "interim solution".


    --
    Gruß, Greetings

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Herbert Kleebauer@21:1/5 to All on Wed Feb 19 01:33:18 2025
    On 19.02.2025 00:53, wolfgang bauer (D) wrote:

    write then the character over it. But I would prefer a simpler solution. And my problem is: How
    can I calculate in realtime the dimensions of that rectangle ? I don't want to have to determine the
    values by experimenting. I'm currently doing this as an "interim solution".

    Here you will find a link to the metrics files for the base 14 Fonts:

    https://stackoverflow.com/questions/6383511/font-metrics-for-the-base-14-fonts-in-the-pdf-specification

    Instead of generating a pdf file, you could create a PostScript file (in PS
    you can calculate the size of a text output using "stringwidth") and then convert the PS to pdf by GhostScript.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Flynn@21:1/5 to All on Wed Feb 19 12:51:00 2025
    On 18/02/2025 23:53, wolfgang bauer (D) wrote:
    18.02.25 , 23:43 , Herbert Kleebauer:

    On 18.02.2025 18:54, wolfgang bauer (D) wrote:

    I want to write a program, that creates a pdf-file. It works. But
    I need to define not only the foreground-color of characters but
    also the background color.
    [...]
    It works. Thank you for the answer. But it is not exactly, what I
    meant. I want to define the background color of every single
    character. I can try, what you suggested, to draw an rectangle in
    the wanted color and write then the character over it. But I would
    prefer a simpler solution. And my problem is: How can I calculate in
    realtime the dimensions of that rectangle ? I don't want to have to determine the values by experimenting. I'm currently doing this as an "interim solution".

    Much easier to use LaTeX, then you have proper control over the size and
    shape and the colours, and it knows the bounding-box of every character
    (and you could also make it set each character in a calculated size of
    box): see the PDF at https://latex.silmaril.ie/col.pdf

    \documentclass{article}
    \usepackage{fontspec}
    \setmainfont{Verdana}
    \usepackage[svgnames]{xcolor} \newcommand{\bgc}[3]{{\colorbox{#1}{\textcolor{#2}{#3}}}}
    \begin{document}
    \Huge\fboxsep0pt\fboxrule0pt
    \bgc{Red}{Green}{H}%
    \bgc{Orange}{Green}{e}%
    \bgc{Yellow}{Green}{l}%
    \bgc{Green}{Green}{l}%
    \bgc{Blue}{Green}{o}%
    \
    \bgc{Indigo}{Blue}{W}%
    \bgc{Violet}{Blue}{o}%
    \bgc{CornflowerBlue}{Blue}{r}%
    \bgc{PaleGreen}{Blue}{l}%
    \bgc{Pink}{Blue}{d}

    \fboxsep2pt
    \bgc{Red}{Pink}{H}%
    \bgc{Orange}{Pink}{e}%
    \bgc{Yellow}{Pink}{l}%
    \bgc{Green}{Pink}{l}%
    \bgc{Blue}{Pink}{o}%
    \
    \bgc{Indigo}{Grey}{W}%
    \bgc{Violet}{Grey}{o}%
    \bgc{CornflowerBlue}{Grey}{r}%
    \bgc{PaleGreen}{Grey}{l}%
    \bgc{Pink}{Grey}{d}
    \end{document}

    Peter

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From wolfgang bauer (D)@21:1/5 to All on Wed Feb 19 20:30:03 2025
    Thank you for the suggestions. I'll put something together and take a closer look at PostScript and LaTeX first.
    And then I might have the result of my program converted to PDF via script, so that the whole thing only costs
    one mouse click, as intended.





    --
    Gruß, Greetings

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)