Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DPI to GlyphOptions to indicate the DPI for glyph rasterization #2597

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Added DPI option to GlyphOptions to indicate the DPI for glyph raster…

…ization
  • Loading branch information
fschutt committed Mar 31, 2018
commit a8e9f3eb0e1b7e045ce74a49cd53a30ff0dba1e7

Some generated files are not rendered by default. Learn more.

@@ -689,6 +689,7 @@ impl<'a> DisplayListFlattener<'a> {
item.glyphs(),
item.display_list().get(item.glyphs()).count(),
text_info.glyph_options,
text_info.glyph_options.and_then(|options| options.dpi),
);
}
SpecificDisplayItem::Rectangle(ref info) => {
@@ -2010,6 +2011,7 @@ impl<'a> DisplayListFlattener<'a> {
glyph_range: ItemRange<GlyphInstance>,
glyph_count: usize,
glyph_options: Option<GlyphOptions>,
dpi: Option<u32>,
) {
let prim = {
let instance_map = self.font_instances.read().unwrap();
@@ -2074,6 +2076,7 @@ impl<'a> DisplayListFlattener<'a> {
flags,
font_instance.platform_options,
font_instance.variations.clone(),
dpi,
);
TextRunPrimitiveCpu {
font: prim_font,
@@ -147,6 +147,9 @@ pub struct FontInstance {
// or something similar to that.
pub size: Au,
pub color: ColorU,
/// DPI of the monitor that this font will be rendered with.
/// Used by `FT_Set_Char_Size`. If set to `None`, will be 72 DPI
pub dpi: Option<u32>,
pub bg_color: ColorU,
pub render_mode: FontRenderMode,
pub subpx_dir: SubpixelDirection,
@@ -167,11 +170,13 @@ impl FontInstance {
flags: FontInstanceFlags,
platform_options: Option<FontInstancePlatformOptions>,
variations: Vec<FontVariation>,
dpi: Option<u32>,
) -> Self {
FontInstance {
font_key,
size,
color: color.into(),
dpi,
bg_color,
render_mode,
subpx_dir,
@@ -305,14 +305,15 @@ impl FontContext {
yx: (shape.skew_y * -65536.0) as FT_Fixed,
yy: (shape.scale_y * 65536.0) as FT_Fixed,
};
let dpi = font.dpi.unwrap_or(72);
unsafe {
FT_Set_Transform(face.face, &mut ft_shape, ptr::null_mut());
FT_Set_Char_Size(
face.face,
(req_size * x_scale * 64.0 + 0.5) as FT_F26Dot6,
(req_size * y_scale * 64.0 + 0.5) as FT_F26Dot6,
0,
0,
dpi,
dpi,
)
}
};
@@ -1525,6 +1525,7 @@ impl Renderer {
}
})?;

let dpi = options.dpi;
thread::Builder::new().name(rb_thread_name.clone()).spawn(move || {
register_thread_with_profiler(rb_thread_name.clone());
if let Some(ref thread_listener) = *thread_listener_for_render_backend {
@@ -1537,6 +1538,7 @@ impl Renderer {
texture_cache,
glyph_rasterizer,
blob_image_renderer,
dpi,
);

let mut backend = RenderBackend::new(
@@ -3854,6 +3856,8 @@ pub trait ThreadListener {

pub struct RendererOptions {
pub device_pixel_ratio: f32,
/// DPI of the monitor
pub dpi: Option<u32>,
pub resource_override_path: Option<PathBuf>,
pub enable_aa: bool,
pub enable_dithering: bool,
@@ -3882,6 +3886,7 @@ impl Default for RendererOptions {
fn default() -> Self {
RendererOptions {
device_pixel_ratio: 1.0,
dpi: None,
resource_override_path: None,
enable_aa: true,
enable_dithering: true,
@@ -254,7 +254,7 @@ pub struct ResourceCache {
cached_glyphs: GlyphCache,
cached_images: ImageCache,
cached_render_tasks: RenderTaskCache,

dpi: Option<u32>,
resources: Resources,
state: State,
current_frame_id: FrameId,
@@ -278,6 +278,7 @@ impl ResourceCache {
texture_cache: TextureCache,
glyph_rasterizer: GlyphRasterizer,
blob_image_renderer: Option<Box<BlobImageRenderer>>,
dpi: Option<u32>,
) -> Self {
ResourceCache {
cached_glyphs: GlyphCache::new(),
@@ -291,6 +292,7 @@ impl ResourceCache {
pending_image_requests: FastHashSet::default(),
glyph_rasterizer,
blob_image_renderer,
dpi,
}
}

@@ -426,6 +428,7 @@ impl ResourceCache {
flags,
platform_options,
variations,
self.dpi,
);
self.resources.font_instances
.write()
@@ -199,13 +199,16 @@ impl Hash for FontVariation {
pub struct GlyphOptions {
pub render_mode: FontRenderMode,
pub flags: FontInstanceFlags,
/// The DPI used for rasterizing this font
pub dpi: Option<u32>,
}

impl Default for GlyphOptions {
fn default() -> Self {
GlyphOptions {
render_mode: FontRenderMode::Subpixel,
flags: FontInstanceFlags::empty(),
dpi: None,
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.