Premultiply small text bitmap when Skia is enabled.

On macOS, bitmaps are created with alpha format by default. When a text
character is rendered relatively small, it uses DrawNormalTextHelper()
to do gamma adjusting, which results in a bitmap that's not
premultiplied.

To avoid crashing the pre-multiplied check for Skia, this CL
premultiplies such text bitmaps after gamma adjusting is done.

Bug: pdfium:1757
Change-Id: I36fd500b42ac018f91060450ccd00747e77d7d6e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/87735
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index c039556..dd472d5 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -1210,6 +1210,14 @@
     DrawNormalTextHelper(bitmap, pGlyph, nrows, point->x, point->y, start_col,
                          end_col, normalize, x_subpixel, a, r, g, b);
   }
+
+#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATH_)
+  // DrawNormalTextHelper() can result in unpremultiplied bitmaps for rendering
+  // glyphs. Make sure `bitmap` is premultiplied before proceeding or
+  // CFX_DIBBase::DebugVerifyBufferIsPreMultiplied() check will fail.
+  bitmap->PreMultiply();
+#endif
+
   if (bitmap->IsMaskFormat())
     SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color);
   else