platform/desktop/directwriteglyph
윈도우 DirectWrite 글리프 마스크. (데스크탑 글리프 래스터가 쓴다)
- 원본에 없는 파일이다. 원본 크롬 윈도우는 Canvas2D 글자를 스키아 SkScalerContext_DW 가 DirectWrite 로 칠한다. 러스트 판도 같은 DirectWrite 호출로 칠한다. (크롬 158 의 스키아 3279352f, src/ports/SkScalerContext_win_dw.cpp, SkTypeface_win_dw.cpp)
- A8 마스크: IDWriteFactory2::CreateGlyphRunAnalysis 에 렌더링 모드(gasp 표, 크기, 바이트코드 힌트, 비트맵 글꼴로 고름), 측정 모드, 격자 맞춤 켬(힌팅 kNormal), 안티에일리어스 그레이스케일을 주고 DWRITE_TEXTURE_ALIASED_1x1 의 알파 텍스처를 받는다. ClearType 이 켜진 기계는 크롬이 글자를 LCD 로 두어 캔버스에서 kGenA8FromLCD 가 걸리므로, IDWriteFactory 로 ClearType 3x1 텍스처를 받아 세 채널 평균을 낸다. (RGBToA8) 서브픽셀 자리는 글자 행렬의 dx, 가짜 기울임은 글자 행렬의 m21(-1/4)이다. 그 뒤 스키아처럼 감마 전보정 표로 고친다. (GrayscaleToA8)
- 글자 대비와 감마: 크롬 158 은 HKCU\SOFTWARE\Microsoft\Avalon.Graphics\<주 화면 장치> 키가 있을 때만 IDWriteRenderingParams 의 값을, 없으면 스키아 기본(대비 1, sRGB)을 쓴다. (ui/gfx/font_util_win.cc GetTextParameters, font_render_params_win.cc, skia/ext/legacy_display_globals.cc 의 SetCachedParams)
Windows DirectWrite glyph mask. (used by the desktop glyph raster)
- A file that does not exist in the original. Original Chrome on Windows paints Canvas2D text with Skia's SkScalerContext_DW through DirectWrite. The Rust version also paints with the same DirectWrite calls. (Skia 3279352f of Chrome 158, src/ports/SkScalerContext_win_dw.cpp, SkTypeface_win_dw.cpp)
- A8 mask: IDWriteFactory2::CreateGlyphRunAnalysis is given a rendering mode (picked by the gasp table, size, bytecode hints and bitmap fonts), a measuring mode, grid fitting on (hinting kNormal) and grayscale antialiasing, and returns an alpha texture of DWRITE_TEXTURE_ALIASED_1x1. On a machine with ClearType on, Chrome treats text as LCD so kGenA8FromLCD applies on the canvas, so a ClearType 3x1 texture is taken from IDWriteFactory and the three channels are averaged. (RGBToA8) The subpixel position is dx of the text matrix, and fake italic is m21 (-1/4) of the text matrix. After that it is corrected with the gamma precorrection table like Skia. (GrayscaleToA8)
- Text contrast and gamma: Chrome 158 uses the IDWriteRenderingParams values only if the key HKCU\SOFTWARE\Microsoft\Avalon.Graphics\<primary display device> exists, otherwise it uses Skia's defaults (contrast 1, sRGB). (GetTextParameters in ui/gfx/font_util_win.cc, font_render_params_win.cc, SetCachedParams in skia/ext/legacy_display_globals.cc)
#[cfg(windows)]
{
use vanilla::platform::desktop::directwriteglyph::DirectWriteGlyphMask;
let _ = std::mem::size_of::<DirectWriteGlyphMask>();
}DirectWriteGlyphMaskstruct
글리프 마스크. (덮인 정도와 상자, 위가 양수인 top_y)
Glyph mask. (coverage and box, with top_y positive upward)
#[cfg(windows)]
fn read_row_length(mask: &vanilla::platform::desktop::directwriteglyph::DirectWriteGlyphMask) -> usize {
mask.width as usize
}
let _ = 0;덮인 정도. (한 줄에 width 바이트, 위 줄부터)
Coverage. (width bytes per row, top row first)
반환ReturnsVec<u8>
펜 원점에서 위 끝. (픽셀, 위가 양수)
Top edge from the pen origin. (pixels, positive upward)
반환Returnsi32
함수Functions
크롬 윈도우의 글자 대비와 감마. ((대비, 감마), 감마 0 은 sRGB)
- 크롬처럼 주 화면 장치의 Avalon.Graphics 키가 있을 때만 DirectWrite 렌더링 값을 쓰고, 없으면 스키아 기본 대비 1, sRGB 다.
Text contrast and gamma of Chrome on Windows. ((contrast, gamma), gamma 0 is sRGB)
- Like Chrome, the DirectWrite rendering values are used only when the Avalon.Graphics key of the primary display device exists, otherwise it is Skia's default of contrast 1 and sRGB.
반환Returns(f32, f32) (대비, 감마). 감마 0 은 sRGB 다.(contrast, gamma). Gamma 0 is sRGB.
크롬 윈도우가 글자를 LCD 로 다루는지. (ClearType 이면 블링크가 kSubpixelAntiAlias 로 두고, 캔버스는 화소 배열을 모르니 스키아가 A8 에 kGenA8FromLCD 를 건다)
- 크롬 font_render_params_win.cc: SPI_GETFONTSMOOTHING 이 켜졌고 SPI_GETFONTSMOOTHINGTYPE 이 ClearType 이면 GetSubpixelRenderingGeometry 가 Avalon.Graphics 의 PixelStructure(0 없음, 1 RGB, 2 BGR, 그 밖은 없음), 그 값이 없으면 SPI_GETFONTSMOOTHINGORIENTATION(RGB, BGR, 그 밖은 없음)이다. 렌더러는 이 값이 없음이 아니면 LCD 글자를 켠다. (web_view_impl.cc 의 SetLCDTextEnabled)
Whether Chrome on Windows treats text as LCD. (If ClearType, Blink sets kSubpixelAntiAlias, and since the canvas does not know the pixel layout Skia applies kGenA8FromLCD to A8)
- Chrome font_render_params_win.cc: if SPI_GETFONTSMOOTHING is on and SPI_GETFONTSMOOTHINGTYPE is ClearType, GetSubpixelRenderingGeometry is PixelStructure of Avalon.Graphics (0 none, 1 RGB, 2 BGR, anything else none), and if that value is missing, SPI_GETFONTSMOOTHINGORIENTATION (RGB, BGR, anything else none). The renderer turns on LCD text if this value is not none. (SetLCDTextEnabled in web_view_impl.cc)
반환Returnsbool LCD 글자를 켜면 true.True if LCD text is on.
pub fn rasterize_glyph_mask(font_bytes: &Rc<[u8]>, source_path: Option<&Path>, face_index: u32, variation_list: &[(u32, f32)], glyph_index: u16, rendering_mode: i32, measuring_mode: i32, render_size: f32, subpixel_x: f32, skew_x: f32, correcting_table: Option<&[u8; 256]>) -> Option<DirectWriteGlyphMask>#DirectWrite 로 글리프 A8 마스크 그리기. (스키아 SkScalerContext_DW::generateDWMetrics, getDWMaskBits, GrayscaleToA8)
Draw a glyph A8 mask with DirectWrite. (Skia SkScalerContext_DW::generateDWMetrics, getDWMaskBits, GrayscaleToA8)
- font_bytes&Rc<[u8]>
- 글꼴 바이트. (캐시 열쇠이고, 파일 경로가 없으면 이것으로 짓는다)Font bytes. (the cache key, and used to build the face when there is no file path)
- source_pathOption<&Path>
- 글꼴 파일 경로.Font file path.
- face_indexu32
- 얼굴 번호.Face index.
- variation_list&[(u32, f32)]
- 축 값. ((4 글자 태그의 수, 값), 비었으면 기본 인스턴스)Axis values. ((number of a 4-character tag, value), empty for the default instance)
- glyph_indexu16
- 글리프 번호.Glyph ID.
- rendering_modei32
- DWRITE_RENDERING_MODE 값. (스키아처럼 gasp 표와 크기로 고른 것)DWRITE_RENDERING_MODE value. (picked from the gasp table and size, like Skia)
- measuring_modei32
- DWRITE_MEASURING_MODE 값.DWRITE_MEASURING_MODE value.
- render_sizef32
- 그릴 글자 크기. (em 크기, 픽셀)Font size to draw. (em size, pixels)
- subpixel_xf32
- 서브픽셀 가로 자리. (0 ~ 1)Horizontal subpixel position. (0 to 1)
- skew_xf32
- 가로 기울기. (가짜 기울임이면 -1/4, 스키아 fPreSkewX 를 DirectWrite 글자 행렬 m21 로)Horizontal slant. (-1/4 for fake italic, Skia fPreSkewX as m21 of the DirectWrite text matrix)
- correcting_tableOption<&[u8; 256]>
- 감마 전보정 표. (None 이면 고치지 않는다)Gamma precorrection table. (None means no correction)
반환ReturnsOption<DirectWriteGlyphMask> 마스크. 윤곽이 없거나 DirectWrite 가 그리지 못하면 None.Mask. None if there is no outline or DirectWrite cannot draw it.