Menu

'font' command doesn't work with variables

Anonymous
2024-03-02
2024-04-05
  • Anonymous

    Anonymous - 2024-03-02

    I'm trying to create a page using different sizes of text.

    If I use "font Lines bold 6", it works as expected.

    If I use ...

    set $text_size 6
    font  Lines bold $text_size
    

    ...any "text" commands after this use a truetype font with a default size. Doesn't matter if I set $text_size to 6 or 16 or 60.

    I also tried using ...

    set $text_size 6
    font  Lines bold
    font $text_size
    

    Same result - the text uses the default truetype font and doesn't change the size at all.

    I'm not familiar with the code base, and I haven't done any java programming since (1997 maybe?) so I don't even know where to start looking in the code to figure this out for myself.

     
    • A. Vontobel

      A. Vontobel - 2024-03-03

      Both examples should actually work. Just try to omit the dollar sign in the "set" command.

      set text_size 10
      font  Lines bold $text_size
      m 15 15
      text "Text height $text_size mm."
      
      set text_size 7
      font  Lines bold
      font $text_size
      m 15 35
      text "Text height $text_size mm."
      
       
  • John Simpson

    John Simpson - 2024-03-02

    I thought I had already logged in - this was my question.

     
  • John Simpson

    John Simpson - 2024-03-04

    That was a typo when creating the post, I should have copy/pasted it. The set lines in the actual code do not have $ in them.

    In order to avoid confusion, https://jms1.pub/sf/ has an actual .hcl file which exhibits the problem. I added a variable $fsvar so I only need to change one place to control whether all of the font lines use a literal or a variable as the size. The same location also has PDFs showing the output with this variable set to 0 (specifying sizes as integers, which produces correct output) or set to 1 (specifying sizes with a variable, which makes the text use a truetype font and doesn't set the size at all).

    To me this smells like a bug in the code, but again, my java-fu is weak so I fully expect to be wrong about this. It's entirely possible I mis-understood the documentation in the PDF that came with the download, but if so I mis-understood it about seven times so far.

    FWIW I'm using version 1.32 ... and I also noticed that the download's filename was Drawj2d-1.3.2.zip, which seems like it should be the same version, but the numbering is inconsistent (i.e. 1.3.2 vs 1.32).

     
    • A. Vontobel

      A. Vontobel - 2024-03-04

      You are right, there is an issue. Thanks for reporting it.
      The work-around is to replace $text_size by [float $text_size].

      In your linked example replace the following way (output of "diff -y --suppress-common-lines orginal.hcl modified.hcl")

      set         fsvar       0                                     | set         fsvar       1
          font        $font_name bold $title_size                   |     font        $font_name bold [float $title_size]
          font        $font_name bold $text_size                    |     font        $font_name bold [float $text_size]
          font        $font_name bold $title_size                   |     font        $font_name bold [float $title_size]
          font        $font_name bold $text_size                    |     font        $font_name bold [float $text_size]
          font        $font_name bold $title_size                   |     font        $font_name bold [float $title_size]
          font        $font_name bold $text_size                    |     font        $font_name bold [float $text_size]
      

      The arguments to the font command are evaluated in FontCmd.java (sourceforge.net). Maybe the font command does not recognize the size variable as a number. I eventually will have to debug using the NetBeans IDE.

       
    • A. Vontobel

      A. Vontobel - 2024-03-18

      The issue will be fixed in the next version. Thanks for reporting.

       
      • A. Vontobel

        A. Vontobel - 2024-04-05

        Drawj2d version 1.3.3 released. The issue "font command doesn't work with variables" should be fixed.

         
  • John Simpson

    John Simpson - 2024-03-04

    That work-around did indeed work, thank you.

    Other than in a list of keywords at the end of the PDF, is the [float ___] function documented anywhere? If there's documentation out there, separate from the PDF, I'd like to read through that as well.

     
    • Anonymous

      Anonymous - 2024-03-05

      The drawj2d vector graphics language uses and extends the Hecl scripting language. Its core commands are listed here.

      In the case of the drawj2d font command ideally it would not be necessary to call [float $size]. Let's see if I can fix it without an incompatible change.

      A few other drawj2d commands might require float if you want to allow integer input. For non-programmers this might be surprising.

          set L 2.0
          puts [format "Length: %.2f m" $L ]
      

      or

          set L 2
          puts [format "Length: %.2f m" [float $L] ]
      
       

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB