JSFX Text Scaling: Seeking Testers for macOS & Linux

Discussion in 'Reaper' started by Sinus Well, May 15, 2025 at 10:56 PM.

  1. Sinus Well

    Sinus Well Audiosexual

    Joined:
    Jul 24, 2019
    Messages:
    2,159
    Likes Received:
    1,677
    Location:
    Sanatorium
    Hey community,

    I'm looking for testers among you who use macOS or Linux for a small JSFX experiment.
    Feedback from Windows users (Win7 or older) is also very welcome.

    In the past, I've encountered some challenges regarding the correct cross-platform rendering and scaling of text in JSFX.

    If you have a few minutes to spare, it would be great if you could test the provided JSFX and give me your feedback on the text rendering.

    Expected behavior:
    • The text always stays within the bounds of the rectangle.
    • The text is always displayed as large as possible.
    • When changing the font, the text size (relative to filling the rectangle) remains constant.
    • When scaling the plugin window, the text scaling occurs smoothly.
    • At maximum rectangle size (100% width, 100% height) and the plugin window in fullscreen, the text covers the entire screen.
    Does the expected behavior hold true for you?

    Please also describe any deviations or unexpected behavior. It would be helpful if you could state your operating system (including version).

    Thanks in advance to everyone who takes the time and shares their observations. :thanks:

    Code:
    desc:font_size_test
    
    slider1:rect_w=25<1,100,.1>w%
    slider2:rect_h=25<1,100,.1>h%
    slider3:value=50<0,100,.01>value
    slider4:font=0<0,2,1{Arial,Verdana,Times New Roman}>font
    
    @init
    gfx_ext_retina = 1;
    
    font_idx = 1;
    font_size = 100;
    format = "%.2f";
    
    
    function _round(val) ( floor(val + 0.5) );
    
    function hex_to_rgb(hex_color)
    local(r_int, g_int, b_int)
    (
      hex_color = floor(hex_color);
      r_int = floor(hex_color / 65536) % 256;
      g_int = floor(hex_color / 256) % 256;
      b_int = hex_color % 256;
      gfx_r = r_int / 255;
      gfx_g = g_int / 255;
      gfx_b = b_int / 255;
    );
    
    function draw_scaled_text(
      rect_x, rect_y, rect_w, rect_h,  // bounding
      textColor,                       // hex-colro
      value,                           // "text", wert (oder slider-index wenn mode = 1)
      mode,                            // 0 = text/zahl, 1 = slider-enum
      format,                          // formatstring (optional)
      font_idx, font_face, font_size,  // font definition
      show_debug_rect                  // debug box
    )
    local(
      prev_font, text, enum_str,
      text_w, text_h,
      curr_size, scale, was_resized,
      init_size,
      draw_x, draw_y,
      x, y, w, h, orig_alpha
    )
    (
      prev_font = gfx_getfont();
      was_resized = 0;
      text = #dst_text_buffer;
      enum_str = #dst_enum_buffer;
    
      mode == 1 ? (
        strcpy_fromslider(enum_str, floor(value));
     
        format ?
          sprintf(text, format, enum_str) :
          strcpy(text, enum_str);
      ) : (
        format ?
          sprintf(text, format, value) :
          strcpy(text, value);
      );
    
    
      rect_w > 0 && rect_h > 0 ? (
        curr_size = max(4, floor(font_size));
        init_size = curr_size;
    
        font_idx > 0 && font_idx <= 16 && font_face ? (
          gfx_setfont(font_idx, font_face, curr_size);
        ) : font_idx == 0 ? (
          gfx_setfont(0);
          curr_size = gfx_texth;
          init_size = curr_size;
        ) : (
          gfx_setfont(prev_font);
          curr_size = gfx_texth;
          init_size = curr_size;
          font_idx = prev_font;
        );
    
        gfx_measurestr(text, text_w, text_h);
    
        (text_w > rect_w || text_h > rect_h) && font_idx > 0 ? (
          scale = min(
            min(
              (text_w > 0 && rect_w > 0) ? rect_w / text_w : 1,
              (text_h > 0 && rect_h > 0) ? rect_h / text_h : 1
            ),
            1
          );
      
          curr_size = max(4, floor(init_size * scale));
          gfx_setfont(font_idx, font_face, curr_size);
          was_resized = 1;
      
          gfx_measurestr(text, text_w, text_h);
        );
    
        draw_x = rect_x + (rect_w - text_w) / 2;
        draw_y = rect_y + (rect_h - text_h) / 2;
    
        hex_to_rgb(textColor);
        gfx_x = _round(draw_x);
        gfx_y = _round(draw_y);
        gfx_drawstr(text);
    
        show_debug_rect ? (
          orig_alpha = gfx_a;
          gfx_a = 1.0;
      
          x = _round(rect_x);
          y = _round(rect_y);
          w = _round(rect_w);
          h = _round(rect_h);
      
          gfx_rect(x, y, w, h, 0);
      
          gfx_a = orig_alpha;
        );
    
        was_resized && font_idx > 0 ? (
          gfx_setfont(font_idx, font_face, init_size);
        );
      );
      gfx_setfont(prev_font);
    );
    
    
    @gfx 500 250
    
    w = gfx_w / 100 * rect_w;
    h = gfx_h / 100 * rect_h;
    x = gfx_w/2 - w/2;
    y = gfx_h/2 - h/2;
    
    font_face = font == 0 ? "Arial" : (font == 1 ? "Verdana" : "Times New Roman");
    
    draw_scaled_text( x,y,w,h, 0xFFFFFF, value,0,format, font_idx,font_face,font_size*gfx_ext_retina, 1 );
     
    Last edited: May 16, 2025 at 2:35 AM
    • Like Like x 1
    • Interesting Interesting x 1
    • List
  2.  
  3. paul_audioz

    paul_audioz Kapellmeister

    Joined:
    Feb 21, 2023
    Messages:
    132
    Likes Received:
    49
    Would really like to help you, but I have no clue how to name this? I copied and past the code in a file "SinusWell" and put it in the Effects folder, but Reaper does not recognize it. Then I renamed the file to "SinusWell.jsfx-inc", but still no recognition in Reaper.
    I am using windows Reaper v6.67 portable under Wine in MX21 and I use Linus version Reaper v6.75.
    Maybe I have to do something different?
     
  4. Sinus Well

    Sinus Well Audiosexual

    Joined:
    Jul 24, 2019
    Messages:
    2,159
    Likes Received:
    1,677
    Location:
    Sanatorium
    Hey @paul_audioz
    'SinusWell.jsfx' should suffice as the filename. The suffix '*.jsfx-inc' would prevent it from being displayed in the plugin browser, as it is used for dependencies.

    Reaper will need to be restarted, or the plugin browser refreshed (F5 on Windows), for the plugin to be displayed. In the plugin browser, it should then be displayed as 'font_size_test'.
     
  5. paul_audioz

    paul_audioz Kapellmeister

    Joined:
    Feb 21, 2023
    Messages:
    132
    Likes Received:
    49
    Ah, good to know. Here are the results form The Netherlands:
    1. windows Reaper v6.67
    - name is JS: font_size_test [SinusWell.jsfx]
    - w% works, the displayed number gets smaller when w is lower
    - h% works, the displayed number gets smaller when h is lower
    - value changes and shows correct number
    - all 3 fonts work

    2. Linux Reaper v6.75
    - name is JS: font_size_test
    - w% works, the displayed number gets smaller when w is lower
    - h% works, the displayed number gets smaller when h is lower
    - value changes and shows correct number
    - all 3 fonts work

    So the only strange thing is the name of your effect. Reaper Linux does not show my given name SinusWell, only the name you gave it. Where windows Reaper does show my given name.
    But overall I would like to give douze points from Pays Bas.
     
Loading...
Similar Threads - JSFX Text Scaling Forum Date
JSFX: mawi designs 2 NEW EQs Reaper Aug 19, 2023
EQ1979 - Neve 1073 [jsfx] Reaper Dec 8, 2022
Reaper JSFX (Plugins) in Any Daw Software Oct 13, 2022
Sonic Anomaly Free PluginsVst and JSFX format Reaper Jan 17, 2018
extract video speech to text software? Lounge Apr 22, 2025
Loading...