bool Bitmap::blitString(const char *pszStr, int x, int y, u8 bSize) { // verify valid size index if ( bSize > 3 || !pszStr ) return false; // localize pointer (TODO: get rid of this offset) Font *fnt = BWDATA::FontBase[bSize]; if ( !fnt->isValid() ) return false; // verify if drawing should be done if ( x + fnt->getTextWidth(pszStr) < 0 || y + fnt->getTextHeight(pszStr) < 0 || x >= this->width() || y >= this->height() ) return false; // Reference an unsigned character array const u8 *pbChars = (BYTE*)pszStr; u8 lastColor = 0, color = 0; int Xoffset = x, Yoffset = y; // Iterate all characters in the message for ( int c = 0; pbChars[c]; ++c ) { // Perform control character and whitespace functions if ( pbChars[c] <= ' ' ) { switch ( pbChars[c] ) { case 1: // restore last colour color = lastColor; continue; case '\t': // 9 tab Xoffset += fnt->getCharWidth( pbChars[c] ); continue; case '\n': // 10 newline Xoffset = x; Yoffset += fnt->maxHeight(); continue; case 11: // invisible case 20: color = (BYTE)~0; continue; case '\f': // 12 formfeed break; case '\r': // 13 carriage return case 26: continue; case 18: // right align Xoffset += this->width() - fnt->getTextWidth(pszStr) - x; continue; case 19: // center align Xoffset += (this->width() - fnt->getTextWidth(pszStr))/2 - x; continue; case ' ': // space Xoffset += fnt->maxWidth() / 2; continue; default: // colour code lastColor = color; color = gbColorTable[ pbChars[c] ]; continue; } } // Skip if the character is not supported by the font FontChar *fntChr = fnt->getChar( pbChars[c] ); if ( !fntChr->isValid() ) continue; // If the colour is not "invisible" if ( color != ~0 ) { // begin drawing character process for ( int i = 0, pos = 0; pos < fntChr->height() * fntChr->width(); ++i, ++pos ) { // font position pos += fntChr->pixelOffset(i); // x offset int newX = Xoffset + (fntChr->x() + pos % fntChr->width()); if ( newX >= this->width() ) break; if ( newX < 0 ) continue; // y offset int newY = Yoffset + (fntChr->y() + pos / fntChr->width()); if ( newY >= this->height() ) break; if ( newY < 0 ) continue; // blit offset int offset = newY * this->width() + newX; if ( offset >= this->width() * this->height() ) break; if ( offset < 0 ) continue; // Plot pixel this->data[offset] = gbFontColors[color][fntChr->colorMask(i)]; } } // invis colour // Increment the X offset for the width of the character Xoffset += fntChr->width(); } return true; }
bool Bitmap::blitString(const char *pszStr, int x, int y, u8 size) { // verify valid size index if (size > 3 || !pszStr) return false; // localize pointer Font *fnt = fontBase[size]; if (!fnt) return false; // verify if drawing should be done if (x + fnt->getTextWidth(pszStr) < 0 || y + fnt->getTextHeight(pszStr) < 0 || x >= this->getWidth() || y >= this->getHeight()) return false; // Reference an unsigned character array const u8 *pbChars = (u8*) pszStr; u8 lastColor = 0, color = 0; int Xoffset = x, Yoffset = y; // Iterate all characters in the message for (int c = 0; pbChars[c]; ++c) { // Perform control character and whitespace functions if (pbChars[c] <= ' ') { switch (pbChars[c]) { case 1: // restore last colour color = lastColor; continue; case '\t': // 9 tab Xoffset += fnt->getCharWidth( pbChars[c] ); continue; case '\n': // 10 newline Xoffset = x; Yoffset += fnt->maxHeight(); continue; case 11: // invisible case 20: color = (u8)~0; continue; case '\f': // 12 formfeed break; case '\r': // 13 carriage return case 26: continue; case 18: // right align Xoffset += this->getWidth() - fnt->getTextWidth(pszStr) - x; continue; case 19: // center align Xoffset += (this->getWidth() - fnt->getTextWidth(pszStr))/2 - x; continue; case ' ': // space Xoffset += fnt->maxWidth() / 2; continue; default: // colour code lastColor = color; color = gbColorTable[ pbChars[c] ]; continue; } } //Korean support if (GetUserDefaultLangID() == MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN) && IsDBCSLeadByte(pbChars[c]) && !(pbChars[c] == 169 || pbChars[c] == 153)) { this->blitKoreanChar((char*) &pbChars[c], Xoffset, Yoffset, size, color); if (pbChars[++c]) continue; break; } // Skip if the character is not supported by the font FontChar *fntChr = fnt->getChar( pbChars[c] ); if (!fntChr) continue; // If the colour is not "invisible" if ( color != ~0 ) { // begin drawing character process for ( int i = 0, pos = 0; pos < fntChr->getHeight() * fntChr->getWidth(); ++i, ++pos ) { // font position pos += fntChr->pixelOffset(i); // x offset int newX = Xoffset + (fntChr->getX() + pos % fntChr->getWidth()); if ( newX >= this->getWidth() ) break; if ( newX < 0 ) continue; // y offset int newY = Yoffset + (fntChr->getY() + pos / fntChr->getWidth()); if ( newY >= this->getHeight() ) break; if ( newY < 0 ) continue; // blit offset int offset = newY * this->getWidth() + newX; if ( offset >= this->getWidth() * this->getHeight() ) break; if ( offset < 0 ) continue; // Plot pixel this->data[offset] = gbFontColors[color][fntChr->colorMask(i)]; } } // invis colour // Increment the X offset for the width of the character Xoffset += fntChr->getWidth(); } return true; }