| 2757 | } |
| 2758 | |
| 2759 | static void ImFontAtlasBuildRenderLinesTexData(ImFontAtlas* atlas) |
| 2760 | { |
| 2761 | if (atlas->Flags & ImFontAtlasFlags_NoBakedLines) |
| 2762 | return; |
| 2763 | |
| 2764 | // This generates a triangular shape in the texture, with the various line widths stacked on top of each other to allow interpolation between them |
| 2765 | ImFontAtlasCustomRect* r = atlas->GetCustomRectByIndex(atlas->PackIdLines); |
| 2766 | IM_ASSERT(r->IsPacked()); |
| 2767 | for (unsigned int n = 0; n < IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1; n++) // +1 because of the zero-width row |
| 2768 | { |
| 2769 | // Each line consists of at least two empty pixels at the ends, with a line of solid pixels in the middle |
| 2770 | unsigned int y = n; |
| 2771 | unsigned int line_width = n; |
| 2772 | unsigned int pad_left = (r->Width - line_width) / 2; |
| 2773 | unsigned int pad_right = r->Width - (pad_left + line_width); |
| 2774 | |
| 2775 | // Write each slice |
| 2776 | IM_ASSERT(pad_left + line_width + pad_right == r->Width && y < r->Height); // Make sure we're inside the texture bounds before we start writing pixels |
| 2777 | if (atlas->TexPixelsAlpha8 != NULL) |
| 2778 | { |
| 2779 | unsigned char* write_ptr = &atlas->TexPixelsAlpha8[r->X + ((r->Y + y) * atlas->TexWidth)]; |
| 2780 | for (unsigned int i = 0; i < pad_left; i++) |
| 2781 | *(write_ptr + i) = 0x00; |
| 2782 | |
| 2783 | for (unsigned int i = 0; i < line_width; i++) |
| 2784 | *(write_ptr + pad_left + i) = 0xFF; |
| 2785 | |
| 2786 | for (unsigned int i = 0; i < pad_right; i++) |
| 2787 | *(write_ptr + pad_left + line_width + i) = 0x00; |
| 2788 | } |
| 2789 | else |
| 2790 | { |
| 2791 | unsigned int* write_ptr = &atlas->TexPixelsRGBA32[r->X + ((r->Y + y) * atlas->TexWidth)]; |
| 2792 | for (unsigned int i = 0; i < pad_left; i++) |
| 2793 | *(write_ptr + i) = IM_COL32(255, 255, 255, 0); |
| 2794 | |
| 2795 | for (unsigned int i = 0; i < line_width; i++) |
| 2796 | *(write_ptr + pad_left + i) = IM_COL32_WHITE; |
| 2797 | |
| 2798 | for (unsigned int i = 0; i < pad_right; i++) |
| 2799 | *(write_ptr + pad_left + line_width + i) = IM_COL32(255, 255, 255, 0); |
| 2800 | } |
| 2801 | |
| 2802 | // Calculate UVs for this line |
| 2803 | ImVec2 uv0 = ImVec2((float)(r->X + pad_left - 1), (float)(r->Y + y)) * atlas->TexUvScale; |
| 2804 | ImVec2 uv1 = ImVec2((float)(r->X + pad_left + line_width + 1), (float)(r->Y + y + 1)) * atlas->TexUvScale; |
| 2805 | float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts |
| 2806 | atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v); |
| 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | // Note: this is called / shared by both the stb_truetype and the FreeType builder |
| 2811 | void ImFontAtlasBuildInit(ImFontAtlas* atlas) |
no test coverage detected