LCOV - code coverage report
Current view: top level - engine/render - rendertext.h (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 100.0 % 1 1
Test Date: 2026-10-21 06:30:36 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #ifndef RENDERTEXT_H_
       2              : #define RENDERTEXT_H_
       3              : struct Font final
       4              : {
       5              :     struct CharInfo final
       6              :     {
       7              :         float x, y, w, h, offsetx, offsety, advance;
       8              :         int tex;
       9              : 
      10              :     };
      11              : 
      12              :     std::string name;
      13              :     std::vector<Texture *> texs;
      14              :     std::vector<CharInfo> chars;
      15              :     int charoffset, defaultw, defaulth, scale;
      16              :     float bordermin, bordermax, outlinemin, outlinemax;
      17              : 
      18            2 :     Font() {}
      19              : };
      20              : 
      21              : #define FONTH (curfont->scale)
      22              : 
      23              : extern Font *curfont;
      24              : 
      25              : /**
      26              :  * @brief Returns half of the nominal font height.
      27              :  *
      28              :  * Takes no parameters and uses no information about text being rendered, so only
      29              :  * provides the nominal size of 1/2 the height.
      30              :  *
      31              :  * @return half of the font height (curfont->scale)
      32              :  */
      33              : extern int fontwidth();
      34              : 
      35              : extern float textscale;
      36              : 
      37              : /**
      38              :  * @brief Reloads all fonts in the font map.
      39              :  *
      40              :  * If any fonts fail to reload, terminates the program with an error message.
      41              :  */
      42              : extern void reloadfonts();
      43              : 
      44              : /**
      45              :  * @brief Attempts to set the global curfont variable to the passed object.
      46              :  *
      47              :  * No effect if the pointer passed is null.
      48              :  *
      49              :  * @param f the font to attempt to set.
      50              :  */
      51              : extern void setfont(Font *f);
      52              : 
      53              : /**
      54              :  * @brief Attempts to set the global curfont variable with a named entry in fonts global
      55              :  *
      56              :  * If no font exists by the name passed, returns false and curfont remains unchanged.
      57              :  *
      58              :  * @param name the name of the font to search for
      59              :  *
      60              :  * @return true if successfully set curfont, false otherwise
      61              :  */
      62              : extern bool setfont(const char *name);
      63              : 
      64              : /**
      65              :  * @brief Push whatever font is assigned to curfont to the font stack.
      66              :  *
      67              :  * fontstack is a std::stack of font pointers. The value in curfont will be
      68              :  * added to fontstack even if it is null or duplicated.
      69              :  */
      70              : extern void pushfont();
      71              : 
      72              : /**
      73              :  * @brief Pop whatever font is on top of the fontstack to curfont
      74              :  *
      75              :  * fontstack is a std::stack of font pointers. Sets curfont to whatever is on top
      76              :  * of the stack, unless it is empty, in which case nothing happens
      77              :  *
      78              :  * @return true if curfont was assigned, false if no elements to assign
      79              :  */
      80              : extern bool popfont();
      81              : 
      82              : /**
      83              :  * @brief Clamps input sizes to minimum sizes.
      84              :  *
      85              :  * Scales the width and height to maintain existing proportions while keeping
      86              :  * both w and h larger than the minimum sizes. If the width and height are already
      87              :  * larger than minres width and height, no effect.
      88              :  *
      89              :  * @param w width to check/change
      90              :  * @param h height to check/change
      91              :  */
      92              : extern void gettextres(int &w, int &h);
      93              : 
      94              : /**
      95              :  * @brief Finds text with using text_boundsf().
      96              :  *
      97              :  * Creates dummy return values for width and height, and returns only the width.
      98              :  * maxwidth in text_boundsf is set to -1.
      99              :  *
     100              :  * @param str the string to get text width of
     101              :  *
     102              :  * @return the width of the string using text_boundsf()"
     103              :  */
     104              : extern float text_widthf(const char *str);
     105              : extern void text_boundsf(const char *str, float &width, float &height, int maxwidth = -1);
     106              : extern int text_visible(const char *str, float hitx, float hity, int maxwidth);
     107              : extern void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth);
     108              : 
     109              : /**
     110              :  * @brief Finds text with using text_boundsf().
     111              :  *
     112              :  * Creates dummy return values for width and height, and returns only the width.
     113              :  * maxwidth in text_boundsf is set to -1. The resulting value is cast to an integer.
     114              :  *
     115              :  * @param str the string to get text width of
     116              :  *
     117              :  * @return the width of the string using text_boundsf(), rounded to nearest int"
     118              :  */
     119              : extern int text_width(const char *str);
     120              : #endif
        

Generated by: LCOV version 2.0-1