Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GFX library rotate and inverse text options?

Any idea or example for easiest way to print rotated text (only particular text, not the whole display) and inverse text(only) foreground/background colors?

Thanks

Parents
  • Hi 

    1) Regarding rotating text, can you try to run the nrf_gfx_rotation_set(..) function before and after the calls you want rotated? 

    I believe this will change the rotation of those prints only: 

    nrf_gfx_rotation_set(p_lcd, NRF_LCD_ROTATE_90);
    
    // Add your draw calls here
    
    nrf_gfx_rotation_set(p_lcd, NRF_LCD_ROTATE_0);

    2) Regarding printed inverted text, this is not supported out of the box, but it should be possible to support it by making some changes to the nrf_gfx.c file. 

    If you make the following changes in the write_character function I believe it should allow you to write inverted text: 

    static void write_character(nrf_lcd_t const * p_instance,
                                nrf_gfx_font_desc_t const * p_font,
                                uint8_t character,
                                uint16_t * p_x,
                                uint16_t y,
                                uint16_t font_color)
    {
        uint8_t char_idx = character - p_font->startChar;
        uint16_t bytes_in_line = CEIL_DIV(p_font->charInfo[char_idx].widthBits, 8);
    
        if (character == ' ')
        {
            *p_x += p_font->height / 2;
            return;
        }
    
        for (uint16_t i = 0; i < p_font->height; i++)
        {
            for (uint16_t j = 0; j < bytes_in_line; j++)
            {
                for (uint8_t k = 0; k < 8; k++)
                {
                    if ((1 << (7 - k)) &
                        p_font->data[p_font->charInfo[char_idx].offset + i * bytes_in_line + j])
                    {
                        pixel_draw(p_instance, *p_x + j * 8 + k, y + i, font_color);
                    }
                    // This code is added to handle inverted text
                    else
                    {
                        pixel_draw(p_instance, *p_x + j * 8 + k, y + i, inverted_color);
                    }
                    // End of modified segment
                }
            }
        }
    
        *p_x += p_font->charInfo[char_idx].widthBits + p_font->spacePixels;
    }

    Please note that you either have to define the inverted_color value somewhere, or simply use the same font_color and remove the original non-inverted pixel_draw call. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    Thanks for the solutions – the rotation works – my bad – I should try it first before ask, but don’t know why decide (based on scanty description maybe) that this function rotates everything incl. already drawn.

    Didn’t try yet your solution for inverse print, but based on the speed that I monitor how slow the text is printed even with original function that draws only minimum pixels for the glyphs, first will try another approach - with drawing a rectangle for background and then the text with original function and inversed color.

    By the way – could you recommend some image convertor that has compatible output with your gfx library?

    I tried all 3 from this link, but only the last one gives some reasonable result, but colors are awful Frowning2

    Thank you and best regards

  • Hi

    samsam said:
    but don’t know why decide (based on scanty description maybe) that this function rotates everything incl. already drawn.

    To be honest I thought the same, until I discovered that some of the library functions used the rotate functions to only rotate specific elements ;)

    samsam said:
    first will try another approach - with drawing a rectangle for background and then the text with original function and inversed color.

    That sounds like a better way to do it, definitely Slight smile

    samsam said:
    By the way – could you recommend some image convertor that has compatible output with your gfx library?

    I investigated this some years back when asked the same question, and was able to find an online converter that worked OK. 

    Essentially you have to use this online generator to load your image, set the "Used for" setting to 65K Color(2 bytes/pixel: RRRRRGGG GGGBBBBB, for "EDIM2"), and click the "Get C String" button. 

    Then you can copy the C array from the Image data box into your .c or .h file. 

    Please note that the array will be define as uint8, not uint16, so you will have to cast it back to uint16 before you pass it to the gfx library. 

    Best regards
    Torbjørn

Reply
  • Hi

    samsam said:
    but don’t know why decide (based on scanty description maybe) that this function rotates everything incl. already drawn.

    To be honest I thought the same, until I discovered that some of the library functions used the rotate functions to only rotate specific elements ;)

    samsam said:
    first will try another approach - with drawing a rectangle for background and then the text with original function and inversed color.

    That sounds like a better way to do it, definitely Slight smile

    samsam said:
    By the way – could you recommend some image convertor that has compatible output with your gfx library?

    I investigated this some years back when asked the same question, and was able to find an online converter that worked OK. 

    Essentially you have to use this online generator to load your image, set the "Used for" setting to 65K Color(2 bytes/pixel: RRRRRGGG GGGBBBBB, for "EDIM2"), and click the "Get C String" button. 

    Then you can copy the C array from the Image data box into your .c or .h file. 

    Please note that the array will be define as uint8, not uint16, so you will have to cast it back to uint16 before you pass it to the gfx library. 

    Best regards
    Torbjørn

Children
  • Thank you very much,  this online convertor works perfect (even without casting)  - the first so far that works almost "out of the box", else there are plenty of such convertors for Arduino hobbyists, but the bytes order is swapped (little vs big endian)  so for simple example with couple colors is not big deal to change them in any text editor , but for real colorful picture will not work ;)

    Now I'm really confused which of your answers to select as "Verify answers" as all of them were quite useful?

    Best regards

  • Hi 

    I am happy to hear that the converter worked fine for you, I haven't tried it in a while Slight smile

    It is not critical which answer you select, mostly people select the answer that wraps up the case (which would be mine from 4 days ago I guess). 

    Best regards
    Torbjørn

Related