0

Question about multiline text

Hi ,

I am trying to print a text with gltext but I am unable to specify the \n command for putting text to multi line .

for example :

string comment = "testingtesting \n testing testing \n testing testing";

so its just putting  a space instead of new line . any clue how we can get the new line stuff works ?

 

Thanks

8 条评论

  • 0
    Avatar
    Jim Hourihan

    Use gltext.writeNL instead of gltext.write

       -Jim

  • 0
    Avatar
    Kurian O.S

    Thank you Jim writeAtNL done that for me :)

    Thanks Again

  • 0
    Avatar
    Peter Daly

    Hi,

    I am also trying to get this multiline to work. I am looking to setup a slate similar to your simple slate to show the following :

    SHOW :

    SHOT  :

    FRAME RANGE :

    DATE :

    FILENAME :

    ARTIST :

    OUTPUT :

    COMMENT :

     

    The movie output path and comments can be too long for one line,  I would like it to write to a new line when it gets too long.

    Can you give an example how to get gltext.writeAtNL to work.

     

    Thanks

  • 0
    Avatar
    Kurian O.S

            let textCnt = textprs.size()*20;

            let getFps = fps();
            let hourCode = 00;
            let mintCode = int(frame) / int(fps()) / 60 ;
            let secCode = frame % 60;
            let milSecCode = int (frame % fps);

            let getTimeCode = ("TCR : %02d:%02d:%02d:%02d \nThis is a test time code"%(hourCode,mintCode,secCode,milSecCode));

            let text   = getTimeCode,
                b      = gltext.boundsNL(float(56)),
                sh     = b[1] + b[3],
                sw     = b[0] + b[2],
                margin = 6,
                x      = tw -textCnt - 45,
                y      = 50,
                g      = float(grey),
                c      = Color(0, 1, 0, float(op));

            glColor(c);
            gltext.color(c);
            gltext.writeAtNL(x, y, text);

     

    hope it will help you

  • 0
    Avatar
    Peter Daly

    Hi ,

    Thanks I got your code to print on newlines using the /n in strings method.

    What does the gltext.boundsNL() do?

     

    What im really trying to do as an example is get a multiline or a wraparound to work :

    rvio foo.#.exr -overlay watermark " THIS IS A LONG TEXT STRING THAT I WANT TO AUTOMATICALLY SPLIT AND PLACE ON THE NEXT LINE WHEN IT GETS TOO LONG FOR THE SCREEN" 0.8 -o watermark_newlinetest.mov

    The Output I'm hoping will generate and output :

    THIS IS A LONG TEXT STRING THAT I WANT TO
    AUTOMATICALLY SPLIT AND PLACE ON THE NEXT LINE

    So with this working I could potentially call in

    rvio foo.#.exr -overlay watermark \"%(moviePath)s\" 0.8 -o watermark_newlinetest.mov

  • 0
    Avatar
    Jim Hourihan

    Hi Peter, boundsNL returns a four vector with the bounds of the text. So in Achayan's example he's using that to calculate the width (sh) and height (sw) of the box of text that will be rendered. 

    Are you trying to do this as an overlay or a slate? Can you describe what you want the output to look like?

        -Jim

  • 0
    Avatar
    Tony Pelle

    Here's some code that will wrap long text by inserting newlines.  A maximum width in pixels is used to determine when to wrap.  There's also some bits and pieces to deal with alignment and some left/righ/center justification.  Hope this helps.  It doesn't use gltext.writeNL as that outputed the lines in the opposite order (or I had a bug in my code that reversed the lne order :)

        union: VAlign { Top | Bottom | Middle };
        union: HAlign { Left | Right | Center };
        union: Justification { Left | Right | Center };

        \: textHeight( float; )
        {
            return gltext.ascenderHeight() - gltext.descenderDepth();
        }
        
        \: textDepth( float; )
        {
            return gltext.descenderDepth();
        }

        \: textSize( (float,float); string text )
        {
            string[] lines  = string.split( text, "\n" );
        float     w      = 0.0;
        float     h      = 0.0;
        float     yinc    = textHeight();

            for_each( line; lines )
        {
                float[4] b = gltext.bounds( line );
            
            w = math.max( w, b[2] - b[0] );
            h += yinc;
        }
        
        return ( w, h );
        }

        \: _wrapText( string; string text, int maxWidth )
        {
        let (w,h) = textSize(text);
        let (sw,sh) = textSize( " " );
        int remaining = maxWidth;

        // use this list as a stack, push/popping each line
        string[] results;

        // split on whitespace...    
        for_each ( word; string.split( text, " " ) )
        {
                let ( ww, wh ) = textSize(word);
                if ( ( ww + sw ) > remaining )
            {
                results.push_back(word);
                remaining = maxWidth - ww;
            }
                else
            {
                if ( results.size() == 0 )
                        results.push_back(word);
                else
                        results.back() += " %s" % word;

                remaining -= ( ww + sw );
            }
        }
        
        return string.join( results, "\n" );

        }

        \: wrapText( string; string text, int maxWidth )
        {
            if ( text eq nil || text == "" )
            return "";

        string[] results;

        // split on newlines...    
        for_each ( line; string.split( text, "\n" ) )
        {
            results.push_back( _wrapText( line, maxWidth ) );
        }
        
        return string.join( results, "\n" );
        }

        \: _drawText( void; float x, float y, Justification justify, string text )
        {
            string[]    lines = string.split( text, "\n" );
        float[]     widths;
        float        maxW = 0.0;
        float        yinc = textHeight();

            for_each( line; lines )
        {
            let ( w, _ ) = textSize( line );
            widths.push_back( w );
            
            maxW = math.max( w, maxW );
        }

            while ( lines.size() > 0 )
        {
            string line = lines.pop_back();
            float  w    = widths.pop_back();
            
            case ( justify )
            {
                Justification.Left   -> { gltext.writeAt( x, y, line ); }
                Justification.Right  -> { gltext.writeAt( x + maxW - w, y, line ); }
                Justification.Center -> { gltext.writeAt( x + ( maxW - w ) / 2.0, y, line ); }
            }
            
            y += yinc;
        }

        }

        \: drawText( void; Color color, float x, float y, HAlign halign, VAlign valign, int wrapAtWidth, string text )
        {
            if ( text eq nil || text == "" )
            return ;

            gltext.color(color);

            if ( wrapAtWidth > 0 )
                text = wrapText( text, wrapAtWidth );

        let (w,h)      = textSize(text);

            case ( halign )
        {
            HAlign.Right    -> { x -= w; }
            HAlign.Center   -> { x -= ( w / 2.0 ); }
        }

            case ( valign )
        {
            VAlign.Top        -> { y -= h; }
            VAlign.Middle   -> { y -= ( h / 2.0 ); }
            VAlign.Bottom   -> { y -= gltext.descenderDepth(); }
        }

            _drawText( x, y, Justification.Left, text );
        }

  • 0
    Avatar
    Emmanuel Dumont

    Thanks for sharing this one Tony. I'll give it a try.

请先登录再写评论。