Doxygen fix.
[bertos.git] / gfx / text.c
index 9c96c983c3613c0254e7ef1bba54eb04e6fa7598..46e3567dbb326f2435951407ed63621bf995a163 100755 (executable)
 
 /*#*
  *#* $Log$
+ *#* Revision 1.11  2006/05/15 07:21:06  bernie
+ *#* Doxygen fix.
+ *#*
+ *#* Revision 1.10  2006/04/27 05:39:23  bernie
+ *#* Enhance text rendering to arbitrary x,y coords.
+ *#*
+ *#* Revision 1.9  2006/04/11 00:08:24  bernie
+ *#* text_offset(): New function, but I'm not quite confident with the design.
+ *#*
+ *#* Revision 1.8  2006/03/22 09:50:37  bernie
+ *#* Use the same format for fonts and rasters.
+ *#*
+ *#* Revision 1.7  2006/03/20 17:51:55  bernie
+ *#* Cleanups.
+ *#*
+ *#* Revision 1.6  2006/03/13 02:05:54  bernie
+ *#* Mark slow paths as UNLIKELY.
+ *#*
  *#* Revision 1.5  2006/03/07 22:18:04  bernie
  *#* Correctly compute text width for prop fonts; Make styles a per-bitmap attribute.
  *#*
 #include <cfg/debug.h>
 
 
-/*! ANSI escape sequences flag: true for ESC state on */
+/**
+ * ANSI escape sequences flag: true for ESC state on.
+ *
+ * \todo Move to Bitmap.flags.
+ */
 static bool ansi_mode = false;
 
+/*!
+ * Move (imaginary) cursor to coordinates specified.
+ */
+void text_setCoord(struct Bitmap *bm, int x, int y)
+{
+       bm->penX = x;
+       bm->penY = y;
+}
+
 
 /*!
  * Move (imaginary) cursor to column and row specified.
  * Next text write will start a that row and col.
  */
-void text_moveto(struct Bitmap *bm, int row, int col)
+void text_moveTo(struct Bitmap *bm, int row, int col)
 {
        ASSERT(col >= 0);
        ASSERT(col < bm->width / bm->font->width);
        ASSERT(row >= 0);
        ASSERT(row < bm->height / bm->font->height);
 
-       bm->penX = col * bm->font->width;
-       bm->penY = row * bm->font->height;
-}
-
-
-/*!
- * Move (imaginary) cursor to coordinates specified.
- */
-void text_setcoord(struct Bitmap *bm, int x, int y)
-{
-       bm->penX = x;
-       bm->penY = y;
+       text_setCoord(bm, col * bm->font->width, row * bm->font->height);
 }
 
 
@@ -135,10 +155,10 @@ static int text_putglyph(char c, struct Bitmap *bm)
        unsigned char index = (unsigned char)c;
 
        /* Check for out of range char and replace with '?' or first char in font. */
-       if (index < bm->font->first || index > bm->font->last)
+       if (UNLIKELY(!FONT_HAS_GLYPH(bm->font, index)))
        {
                kprintf("Illegal char '%c' (0x%02x)\n", index, index);
-               if ('?' >= bm->font->first && '?' <= bm->font->last)
+               if (FONT_HAS_GLYPH(bm->font, '?'))
                        index = '?';
                else
                        index = bm->font->first;
@@ -149,7 +169,7 @@ static int text_putglyph(char c, struct Bitmap *bm)
 
        glyph_height = bm->font->height;
        // FIXME: for vertical fonts only
-       glyph_height_bytes = (glyph_height + 7) / 8;
+       glyph_height_bytes = ROUND_UP2(glyph_height, 8);
 
        if (bm->font->offset)
        {
@@ -172,8 +192,9 @@ static int text_putglyph(char c, struct Bitmap *bm)
        }
 
        /* Slow path for styled glyphs */
-       if (bm->styles)
+       if (UNLIKELY(bm->styles))
        {
+               uint8_t styles = bm->styles;
                uint8_t prev_dots = 0, italic_prev_dots = 0;
                uint8_t dots;
                uint8_t row, col;
@@ -202,14 +223,14 @@ static int text_putglyph(char c, struct Bitmap *bm)
                                uint8_t i;
 
                                /* Expanded style: advances only once every two columns. */
-                               if (bm->styles & STYLEF_EXPANDED)
+                               if (styles & STYLEF_EXPANDED)
                                        src_col /= 2;
 
                                /* Fetch a column of dots from glyph. */
-                               dots = PGM_READ_CHAR(glyph + src_col * glyph_height_bytes + row);
+                               dots = PGM_READ_CHAR(RAST_ADDR(glyph, src_col, row * 8, glyph_width));
 
                                /* Italic: get lower 4 dots from previous column */
-                               if (bm->styles & STYLEF_ITALIC)
+                               if (styles & STYLEF_ITALIC)
                                {
                                        uint8_t new_dots = dots;
                                        dots = (dots & 0xF0) | italic_prev_dots;
@@ -217,7 +238,7 @@ static int text_putglyph(char c, struct Bitmap *bm)
                                }
 
                                /* Bold: "or" pixels with the previous column */
-                               if (bm->styles & STYLEF_BOLD)
+                               if (styles & STYLEF_BOLD)
                                {
                                        uint8_t new_dots = dots;
                                        dots |= prev_dots;
@@ -225,11 +246,12 @@ static int text_putglyph(char c, struct Bitmap *bm)
                                }
 
                                /* Underlined: turn on base pixel */
-                               if (bm->styles & STYLEF_UNDERLINE)
-                                       dots |= 0x80;
+                               if ((styles & STYLEF_UNDERLINE)
+                                       && (row == glyph_height_bytes - 1))
+                                       dots |= (1 << (glyph_height - row * 8 - 1));
 
                                /* Inverted: invert pixels */
-                               if (bm->styles & STYLEF_INVERT)
+                               if (styles & STYLEF_INVERT)
                                        dots = ~dots;
 
                                /* Output dots */
@@ -241,7 +263,7 @@ static int text_putglyph(char c, struct Bitmap *bm)
        else
        {
                /* No style: fast vanilla copy of glyph to bitmap */
-               gfx_blitRaster(bm, bm->penX, bm->penY, glyph, glyph_width, glyph_height, glyph_height_bytes);
+               gfx_blitRaster(bm, bm->penX, bm->penY, glyph, glyph_width, glyph_height, glyph_width);
        }
 
        /* Update current pen position */
@@ -258,7 +280,7 @@ static int text_putglyph(char c, struct Bitmap *bm)
 int text_putchar(char c, struct Bitmap *bm)
 {
        /* Handle ANSI escape sequences */
-       if (ansi_mode)
+       if (UNLIKELY(ansi_mode))
        {
                switch (c)
                {
@@ -309,9 +331,10 @@ void text_clearLine(struct Bitmap *bm, int line)
 }
 
 
-/*!
+/**
  * Set/clear algorithmic font style bits.
  *
+ * \param bm     Pointer to Bitmap to affect.
  * \param flags  Style flags to set
  * \param mask   Mask of flags to modify
  * \return       Old style flags