@@ -775,12 +775,6 @@ impl DirectWriteState {
)?;
}
- let antialias_mode = if params.is_emoji {
- DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE
- } else {
- DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE
- };
-
let glyph_analysis = unsafe {
self.components.factory.CreateGlyphRunAnalysis(
&glyph_run,
@@ -788,7 +782,7 @@ impl DirectWriteState {
rendering_mode,
DWRITE_MEASURING_MODE_NATURAL,
grid_fit_mode,
- antialias_mode,
+ DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE,
baseline_origin_x,
baseline_origin_y,
)
@@ -854,48 +848,41 @@ impl DirectWriteState {
anyhow::bail!("glyph bounds are empty");
}
- let bitmap_size = glyph_bounds.size;
-
- let mut bitmap_data: Vec<u8>;
- if params.is_emoji {
- let glyph_analysis = self.create_glyph_run_analysis(params)?;
-
+ let bitmap_data = if params.is_emoji {
if let Ok(color) = self.rasterize_color(¶ms, glyph_bounds) {
- bitmap_data = color;
+ color
} else {
- let monochrome = self.rasterize_monochrome(&glyph_analysis, glyph_bounds)?;
- bitmap_data = monochrome
+ let monochrome = self.rasterize_monochrome(params, glyph_bounds)?;
+ monochrome
.into_iter()
.flat_map(|pixel| [0, 0, 0, pixel])
- .collect::<Vec<_>>();
+ .collect::<Vec<_>>()
}
} else {
- let glyph_analysis = self.create_glyph_run_analysis(params)?;
- bitmap_data = self.rasterize_monochrome(&glyph_analysis, glyph_bounds)?;
- }
+ self.rasterize_monochrome(params, glyph_bounds)?
+ };
- Ok((bitmap_size, bitmap_data))
+ Ok((glyph_bounds.size, bitmap_data))
}
fn rasterize_monochrome(
&self,
- glyph_analysis: &IDWriteGlyphRunAnalysis,
+ params: &RenderGlyphParams,
glyph_bounds: Bounds<DevicePixels>,
) -> Result<Vec<u8>> {
- let multisampled_bounds =
- unsafe { glyph_analysis.GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1)? };
- let multisampled_size = size(
- multisampled_bounds.right - multisampled_bounds.left,
- multisampled_bounds.bottom - multisampled_bounds.top,
- );
-
let mut bitmap_data =
- vec![0u8; multisampled_size.width as usize * multisampled_size.height as usize * 3];
+ vec![0u8; glyph_bounds.size.width.0 as usize * glyph_bounds.size.height.0 as usize * 3];
+ let glyph_analysis = self.create_glyph_run_analysis(params)?;
unsafe {
glyph_analysis.CreateAlphaTexture(
DWRITE_TEXTURE_CLEARTYPE_3x1,
- &multisampled_bounds,
+ &RECT {
+ left: glyph_bounds.origin.x.0,
+ top: glyph_bounds.origin.y.0,
+ right: glyph_bounds.size.width.0 + glyph_bounds.origin.x.0,
+ bottom: glyph_bounds.size.height.0 + glyph_bounds.origin.y.0,
+ },
&mut bitmap_data,
)?;
}
@@ -903,10 +890,10 @@ impl DirectWriteState {
let bitmap_factory = self.components.bitmap_factory.resolve()?;
let bitmap = unsafe {
bitmap_factory.CreateBitmapFromMemory(
- multisampled_size.width as u32,
- multisampled_size.height as u32,
+ glyph_bounds.size.width.0 as u32,
+ glyph_bounds.size.height.0 as u32,
&GUID_WICPixelFormat24bppRGB,
- multisampled_size.width as u32 * 3,
+ glyph_bounds.size.width.0 as u32 * 3,
&bitmap_data,
)
}?;
@@ -914,20 +901,10 @@ impl DirectWriteState {
let grayscale_bitmap =
unsafe { WICConvertBitmapSource(&GUID_WICPixelFormat8bppGray, &bitmap) }?;
- let scaler = unsafe { bitmap_factory.CreateBitmapScaler() }?;
- unsafe {
- scaler.Initialize(
- &grayscale_bitmap,
- glyph_bounds.size.width.0 as u32,
- glyph_bounds.size.height.0 as u32,
- WICBitmapInterpolationModeHighQualityCubic,
- )
- }?;
-
let mut bitmap_data =
vec![0u8; glyph_bounds.size.width.0 as usize * glyph_bounds.size.height.0 as usize];
unsafe {
- scaler.CopyPixels(
+ grayscale_bitmap.CopyPixels(
std::ptr::null() as _,
glyph_bounds.size.width.0 as u32,
&mut bitmap_data,