3 #include "small_font.h" 4 #include "large_font.h" 10 return writeString(text, p, size, textColor, backgroundColor, maxLength,
false);
14 return writeString(text, p, size, textColor,
KDColorWhite, -1,
true);
19 int characterWidth = size ==
KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH;
20 int characterHeight = size ==
KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT: BITMAP_SmallFont_CHARACTER_HEIGHT;
21 KDPoint characterSize(characterWidth, 0);
23 const char * end = text+maxLength;
24 while(*text != 0 && text != end) {
25 writeChar(*text, position, size, textColor, backgroundColor, transparentBackground);
27 position =
KDPoint(0, position.
y()+characterHeight);
28 }
else if (*text ==
'\t') {
39 if (character ==
'\n' || character ==
'\t') {
42 char firstCharacter = size ==
KDText::FontSize::Large ? BITMAP_LargeFont_FIRST_CHARACTER : BITMAP_SmallFont_FIRST_CHARACTER;
43 int characterHeight = size ==
KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT : BITMAP_SmallFont_CHARACTER_HEIGHT;
44 int characterWidth = size ==
KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH;
48 KDRect absoluteRect = absoluteFillRect(
KDRect(p, characterWidth, characterHeight));
49 if (transparentBackground) {
50 pullRect(absoluteRect, characterBuffer);
54 startingI = startingI < 0 ? 0 : startingI;
55 startingJ = startingJ < 0 ? 0 : startingJ;
59 KDColor * currentPixelAdress = characterBuffer + i + absoluteRect.
width()*j;
uint8_t intensity = 0;
61 intensity = bitmapLargeFont[(
uint8_t)character-(
uint8_t)firstCharacter][j + startingJ][i +startingI];
63 intensity = bitmapSmallFont[(
uint8_t)character-(
uint8_t)firstCharacter][j + startingJ][i +startingI];
65 KDColor backColor = transparentBackground ? *currentPixelAdress : backgroundColor;
66 *currentPixelAdress =
KDColor::blend(textColor, backColor, intensity);
69 pushRect(absoluteRect, characterBuffer);
KDPoint drawString(const char *text, KDPoint p, KDText::FontSize size=KDText::FontSize::Large, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite, int maxLength=-1)
KDColor largeCharacterBuffer[BITMAP_LargeFont_CHARACTER_WIDTH *BITMAP_LargeFont_CHARACTER_HEIGHT]
KDPoint blendString(const char *text, KDPoint p, KDText::FontSize size, KDColor textColor=KDColorBlack)
KDColor smallCharacterBuffer[BITMAP_SmallFont_CHARACTER_WIDTH *BITMAP_SmallFont_CHARACTER_HEIGHT]
virtual void pullRect(KDRect rect, KDColor *pixels)=0
constexpr KDColor KDColorWhite
virtual void pushRect(KDRect, const KDColor *pixels)=0
KDCoordinate width() const
KDPoint translatedBy(KDPoint other) const
KDCoordinate height() const
static KDColor blend(KDColor first, KDColor second, uint8_t alpha)
static constexpr int k_tabCharacterWidth