| 430 | } |
| 431 | |
| 432 | bool getBitmap(const char* text, const FontDefinition& textDefinition, Device::TextAlign eAlignMask) |
| 433 | { |
| 434 | if (libError) |
| 435 | { |
| 436 | return false; |
| 437 | } |
| 438 | |
| 439 | FT_Face face; |
| 440 | std::string fontfile = getFontFile(textDefinition._fontName.c_str()); |
| 441 | if (FT_New_Face(library, fontfile.c_str(), 0, &face)) |
| 442 | { |
| 443 | // no valid font found use default |
| 444 | if (FT_New_Face(library, "/usr/share/fonts/truetype/freefont/FreeSerif.ttf", 0, &face)) |
| 445 | { |
| 446 | return false; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | // select utf8 charmap |
| 451 | if (FT_Select_Charmap(face, FT_ENCODING_UNICODE)) |
| 452 | { |
| 453 | FT_Done_Face(face); |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | if (FT_Set_Pixel_Sizes(face, textDefinition._fontSize, textDefinition._fontSize)) |
| 458 | { |
| 459 | FT_Done_Face(face); |
| 460 | return false; |
| 461 | } |
| 462 | |
| 463 | if (divideString(face, text, textDefinition._dimensions.width, textDefinition._dimensions.height) == false) |
| 464 | { |
| 465 | FT_Done_Face(face); |
| 466 | return false; |
| 467 | } |
| 468 | |
| 469 | // compute the final line width |
| 470 | iMaxLineWidth = MAX(iMaxLineWidth, textDefinition._dimensions.width); |
| 471 | |
| 472 | // compute the final line height |
| 473 | int lineHeight = face->size->metrics.height >> 6; |
| 474 | int txtHeight = (lineHeight * textLines.size()); |
| 475 | iMaxLineHeight = MAX(txtHeight, textDefinition._dimensions.height); |
| 476 | |
| 477 | _data = (unsigned char*)malloc(sizeof(unsigned char) * (iMaxLineWidth * iMaxLineHeight * 4)); |
| 478 | memset(_data, 0, iMaxLineWidth * iMaxLineHeight * 4); |
| 479 | |
| 480 | int iCurYCursor = computeLineStartY(face, eAlignMask, txtHeight, iMaxLineHeight); |
| 481 | |
| 482 | int lineCount = textLines.size(); |
| 483 | |
| 484 | auto&& textColor = Color4B(textDefinition._fontFillColor, textDefinition._fontAlpha); |
| 485 | for (int line = 0; line < lineCount; line++) |
| 486 | { |
| 487 | int iCurXCursor = computeLineStart(face, eAlignMask, line); |
| 488 | |
| 489 | int glyphCount = textLines.at(line).glyphs.size(); |
no test coverage detected