void KDContext::writeChar(char character, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor, bool transparentBackground) { if (character == '\n' || character == '\t') { return; } char firstCharacter = size == KDText::FontSize::Large ? BITMAP_LargeFont_FIRST_CHARACTER : BITMAP_SmallFont_FIRST_CHARACTER; int characterHeight = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT : BITMAP_SmallFont_CHARACTER_HEIGHT; int characterWidth = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH; KDColor * characterBuffer = size == KDText::FontSize::Large ? largeCharacterBuffer : smallCharacterBuffer; KDRect absoluteRect = absoluteFillRect(KDRect(p, characterWidth, characterHeight)); if (transparentBackground) { pullRect(absoluteRect, characterBuffer); } KDCoordinate startingI = m_clippingRect.x() - p.translatedBy(m_origin).x(); KDCoordinate startingJ = m_clippingRect.y() - p.translatedBy(m_origin).y(); startingI = startingI < 0 ? 0 : startingI; startingJ = startingJ < 0 ? 0 : startingJ; for (KDCoordinate j=0; j<absoluteRect.height(); j++) { for (KDCoordinate i=0; i<absoluteRect.width(); i++) { KDColor * currentPixelAdress = characterBuffer + i + absoluteRect.width()*j; uint8_t intensity = 0; if (size == KDText::FontSize::Large) { intensity = bitmapLargeFont[(uint8_t)character-(uint8_t)firstCharacter][j + startingJ][i +startingI]; } else { intensity = bitmapSmallFont[(uint8_t)character-(uint8_t)firstCharacter][j + startingJ][i +startingI]; } KDColor backColor = transparentBackground ? *currentPixelAdress : backgroundColor; *currentPixelAdress = KDColor::blend(textColor, backColor, intensity); } } pushRect(absoluteRect, characterBuffer); }
void EJCanvasContext::fillRect(float x, float y, float w, float h) { setTexture(NULL); EJColorRGBA color = state->fillColor; color.rgba.a = (unsigned char)(color.rgba.a * state->globalAlpha); pushRect(x, y, w, h, 0, 0, 0, 0, color, state->transform); }
void EJCanvasContext::clearRect(float x, float y, float w, float h) { setTexture(NULL); EJCompositeOperation oldOp = state->globalCompositeOperation; globalCompositeOperation = kEJCompositeOperationDestinationOut; static EJColorRGBA white = {0x00000000}; pushRect(x, y, w, h, 0, 0, 0, 0, white, state->transform); globalCompositeOperation = oldOp; }
void EJCanvasContext::putImageData(EJImageData* imageData, float dx, float dy) { EJTexture * texture = imageData->m_texture; setTexture(texture); short tw = texture->realWidth; short th = texture->realHeight; static EJColorRGBA white = {0xffffffff}; pushRect(dx, dy, tw, th, 0, 0, 1, 1, white, CGAffineTransformIdentity); flushBuffers(); }
void EJCanvasContext::drawImage(EJTexture * texture, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { if (texture) { float tw = texture->realWidth; float th = texture->realHeight; //EJColorRGBA color = {{255, 255, 255, 255 * state->globalAlpha}}; EJColorRGBA color = {0xffffffff}; color.rgba.a = (unsigned char)(255 * state->globalAlpha); setTexture(texture); pushRect(dx, dy, dw, dh, sx/tw, sy/th, sw/tw, sh/th, color, state->transform); } }