| 760 | } |
| 761 | |
| 762 | void UploadEntityLayerText(const CImageInfo &TextImage, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) |
| 763 | { |
| 764 | if(FontSize < 1) |
| 765 | return; |
| 766 | |
| 767 | const size_t PixelSize = TextImage.PixelSize(); |
| 768 | const char *pCurrent = pText; |
| 769 | const char *pEnd = pCurrent + Length; |
| 770 | int WidthLastChars = 0; |
| 771 | |
| 772 | while(pCurrent < pEnd) |
| 773 | { |
| 774 | const char *pTmp = pCurrent; |
| 775 | const int NextCharacter = str_utf8_decode(&pTmp); |
| 776 | |
| 777 | if(NextCharacter) |
| 778 | { |
| 779 | FT_Face Face; |
| 780 | FT_UInt GlyphIndex = GetCharGlyph(NextCharacter, &Face, true); |
| 781 | if(GlyphIndex == 0) |
| 782 | { |
| 783 | pCurrent = pTmp; |
| 784 | continue; |
| 785 | } |
| 786 | |
| 787 | FT_Set_Pixel_Sizes(Face, 0, FontSize); |
| 788 | if(FT_Load_Char(Face, NextCharacter, FT_LOAD_RENDER | FT_LOAD_NO_BITMAP)) |
| 789 | { |
| 790 | log_debug("textrender", "Error loading glyph. Chr=%d GlyphIndex=%u", NextCharacter, GlyphIndex); |
| 791 | pCurrent = pTmp; |
| 792 | continue; |
| 793 | } |
| 794 | |
| 795 | const FT_Bitmap *pBitmap = &Face->glyph->bitmap; |
| 796 | if(pBitmap->pixel_mode != FT_PIXEL_MODE_GRAY) |
| 797 | { |
| 798 | log_debug("textrender", "Error loading glyph, unsupported pixel mode. Chr=%d GlyphIndex=%u PixelMode=%d", NextCharacter, GlyphIndex, pBitmap->pixel_mode); |
| 799 | pCurrent = pTmp; |
| 800 | continue; |
| 801 | } |
| 802 | |
| 803 | for(unsigned OffY = 0; OffY < pBitmap->rows; ++OffY) |
| 804 | { |
| 805 | for(unsigned OffX = 0; OffX < pBitmap->width; ++OffX) |
| 806 | { |
| 807 | const int ImgOffX = std::clamp(x + OffX + WidthLastChars, x, (x + TexSubWidth) - 1); |
| 808 | const int ImgOffY = std::clamp(y + OffY, y, (y + TexSubHeight) - 1); |
| 809 | const size_t ImageOffset = ImgOffY * (TextImage.m_Width * PixelSize) + ImgOffX * PixelSize; |
| 810 | for(size_t i = 0; i < PixelSize - 1; ++i) |
| 811 | { |
| 812 | TextImage.m_pData[ImageOffset + i] = 255; |
| 813 | } |
| 814 | TextImage.m_pData[ImageOffset + PixelSize - 1] = pBitmap->buffer[OffY * pBitmap->width + OffX]; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | WidthLastChars += (pBitmap->width + 1); |
| 819 | } |
no test coverage detected