/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::sync::Arc; use std::mem;
use api::{
IdNamespace, FontTemplate, FontKey, FontInstanceKey, FontInstanceOptions,
FontInstancePlatformOptions, ColorF, FontInstanceFlags, units::DevicePoint,
}; use glutin::config::{ConfigTemplateBuilder, GlConfig}; use glutin::context::{
ContextApi, ContextAttributesBuilder, NotCurrentGlContext, Version,
}; use glutin::display::{GetGlDisplay, GlDisplay}; use glutin::surface::{GlSurface, SurfaceAttributesBuilder, WindowSurface}; use glutin_winit::DisplayBuilder; use rayon::ThreadPoolBuilder; use std::num::NonZeroU32; use winit::application::ApplicationHandler; use winit::dpi::PhysicalSize; use winit::event::{WindowEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use wr_glyph_rasterizer::RasterizedGlyph; use wr_glyph_rasterizer::{
SharedFontResources, BaseFontInstance, GlyphRasterizer, FontInstance, GlyphKey,
SubpixelDirection, profiler::GlyphRasterizeProfiler,
};
#[path = "common/boilerplate.rs"] mod boilerplate;
let font_key = FontKey::new(namespace, 0); let raw_font_data = include_bytes!("../../wrench/reftests/text/FreeSans.ttf"); let font_template = FontTemplate::Raw(Arc::new(raw_font_data.to_vec()), 0); let shared_font_key = fonts
.font_keys
.add_key(&font_key, &font_template)
.expect("Failed to add font key");
let font_instance_key = FontInstanceKey::new(namespace, 1);
fonts.templates.add_font(shared_font_key, font_template);
assert!(fonts.templates.has_font(&shared_font_key));
// AddFontInstance will only be processed here, not in the resource cache, so it // is safe to take the options rather than clone them. let base = BaseFontInstance::new(
font_instance_key,
shared_font_key, 32.,
mem::take(&mut Some(FontInstanceOptions::default())),
mem::take(&mut Some(FontInstancePlatformOptions::default())),
mem::take(&mut Vec::new()),
); let shared_instance = fonts
.instance_keys
.add_key(base)
.expect("Failed to add font instance key");
fonts.instances.add_font_instance(shared_instance);
let workers = { let worker = ThreadPoolBuilder::new()
.thread_name(|idx| format!("WRWorker#{}", idx))
.build();
Arc::new(worker.unwrap())
}; letmut glyph_rasterizer = GlyphRasterizer::new(workers, None, false);
glyph_rasterizer.add_font(
shared_font_key,
fonts
.templates
.get_font(&shared_font_key)
.expect("Could not find FontTemplate"),
);
letmut font = FontInstance::new(
fonts
.instances
.get_font_instance(font_instance_key)
.expect("Could not found BaseFontInstance"),
ColorF::BLACK.into(),
api::FontRenderMode::Alpha,
FontInstanceFlags::SUBPIXEL_POSITION | FontInstanceFlags::FONT_SMOOTHING,
);
glyph_rasterizer.prepare_font(&mut font);
let glyph_keys = [
glyph_rasterizer
.get_glyph_index(shared_font_key, 'A')
.expect("Failed to get glyph index"),
glyph_rasterizer
.get_glyph_index(shared_font_key, 'B')
.expect("Failed to get glyph index"),
glyph_rasterizer
.get_glyph_index(shared_font_key, 'C')
.expect("Failed to get glyph index"),
];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.