diff --git a/piet-cairo/examples/test-picture.rs b/piet-cairo/examples/test-picture.rs index 18d59690..dfc759f1 100644 --- a/piet-cairo/examples/test-picture.rs +++ b/piet-cairo/examples/test-picture.rs @@ -9,7 +9,8 @@ use cairo::{Context, Format, ImageSurface}; use piet::{samples, RenderContext}; use piet_cairo::CairoRenderContext; -const HIDPI: f64 = 2.0; +// TODO: Improve support for fractional scaling where sample size ends up fractional. +const SCALE: f64 = 2.0; const FILE_PREFIX: &str = "cairo-test-"; fn main() { @@ -19,7 +20,7 @@ fn main() { fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box> { let sample = samples::get(idx)?; - let size = sample.size(); + let size = sample.size() * SCALE; let file_name = format!("{}{}.png", FILE_PREFIX, idx); let path = base_dir.join(file_name); @@ -27,7 +28,7 @@ fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box Result<(), Box> { let sample = samples::get(idx)?; - let size = sample.size(); + let size = sample.size() * SCALE; let file_name = format!("{}{}.png", FILE_PREFIX, idx); let path = base_dir.join(file_name); let mut cg_ctx = make_cg_ctx(size); - let mut piet_context = - CoreGraphicsContext::new_y_up(&mut cg_ctx, size.height * SCALE.recip(), None); + let mut piet_context = CoreGraphicsContext::new_y_up(&mut cg_ctx, sample.size().height, None); sample.draw(&mut piet_context)?; diff --git a/piet-direct2d/examples/test-picture.rs b/piet-direct2d/examples/test-picture.rs index 1562d96f..0d13fba1 100644 --- a/piet-direct2d/examples/test-picture.rs +++ b/piet-direct2d/examples/test-picture.rs @@ -7,7 +7,8 @@ use winapi::shared::dxgi::DXGI_MAP_READ; use piet::{samples, RenderContext}; use piet_direct2d::{D2DRenderContext, D2DText}; -const HIDPI: f32 = 2.0; +// TODO: Improve support for fractional scaling where sample size ends up fractional. +const SCALE: f32 = 2.0; const FILE_PREFIX: &str = "d2d-test-"; fn main() { @@ -16,7 +17,7 @@ fn main() { fn run_sample(number: usize, base_dir: &Path) -> Result<(), Box> { let sample = samples::get(number)?; - let size = sample.size(); + let size = sample.size() * SCALE as f64; let file_name = format!("{}{}.png", FILE_PREFIX, number); let path = base_dir.join(file_name); @@ -43,10 +44,10 @@ fn run_sample(number: usize, base_dir: &Path) -> Result<(), Box Result<(), Error> { rc.clear(None, Color::WHITE); diff --git a/piet/src/samples/picture_1.rs b/piet/src/samples/picture_1.rs index 632b38fd..47115c27 100644 --- a/piet/src/samples/picture_1.rs +++ b/piet/src/samples/picture_1.rs @@ -3,7 +3,7 @@ use crate::kurbo::{BezPath, Line, Point, Size}; use crate::{Color, Error, RenderContext}; -pub const SIZE: Size = Size::new(400., 200.); +pub const SIZE: Size = Size::new(200., 100.); // TODO: this will eventually become a `kurbo::Shape`. fn circle>(center: V, radius: f64, num_segments: usize) -> BezPath { diff --git a/piet/src/samples/picture_10.rs b/piet/src/samples/picture_10.rs index 90cf6f38..e3a6f76c 100644 --- a/piet/src/samples/picture_10.rs +++ b/piet/src/samples/picture_10.rs @@ -3,7 +3,7 @@ use crate::kurbo::{Size, Vec2}; use crate::{Color, Error, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder}; -pub const SIZE: Size = Size::new(400., 400.); +pub const SIZE: Size = Size::new(200., 200.); static SAMPLE_EN: &str = r#"ḧ́ͥm̾ͭpͭ̒ͦ̎ḧ̐̈̾̆͊ ch̯͈̙̯̼̠a͚͉o̺̮̳̮̩s̪͇.̥̩̹"#; diff --git a/piet/src/samples/picture_11.rs b/piet/src/samples/picture_11.rs index da363c28..42b497f4 100644 --- a/piet/src/samples/picture_11.rs +++ b/piet/src/samples/picture_11.rs @@ -3,7 +3,7 @@ use crate::kurbo::{Circle, Line, Point, Size}; use crate::{Color, Error, RenderContext, Text, TextLayout, TextLayoutBuilder}; -pub const SIZE: Size = Size::new(880., 800.); +pub const SIZE: Size = Size::new(440., 400.); pub const DOT_RADIUS: f64 = 2.0; pub const TEST_ADVANCE: f64 = 23.4; @@ -41,7 +41,7 @@ pub fn draw(rc: &mut R) -> Result<(), Error> { .alignment(crate::TextAlignment::Justified) .max_width(200.0) .build()?; - let ar_y = ((SIZE.height - layout_ar_start.size().height * 2.0) / 2.0 - 32.0).max(0.0); + let ar_y = ((SIZE.height - layout_ar_start.size().height) - 32.0).max(0.0); visualize_hit_testing(rc, layout_en_start, Point::new(16.0, 32.0))?; visualize_hit_testing(rc, layout_en_center, Point::new(232.0, 32.0))?; diff --git a/piet/src/samples/picture_12.rs b/piet/src/samples/picture_12.rs index ecfdb8a8..a6343501 100644 --- a/piet/src/samples/picture_12.rs +++ b/piet/src/samples/picture_12.rs @@ -5,7 +5,7 @@ use crate::{ Color, Error, FontFamily, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder, }; -pub const SIZE: Size = Size::new(480., 560.); +pub const SIZE: Size = Size::new(240., 280.); static TEXT: &str = r#"The idea of "structurelessness," however, has moved from a healthy counter to those tendencies to becoming a goddess in its own right. The idea is as little examined as the term is much used, but it has become an intrinsic and unquestioned part of women's liberation ideology. For the early development of the movement this did not much matter."#; @@ -24,7 +24,7 @@ pub fn draw(rc: &mut R) -> Result<(), Error> { .range_attribute(280.., TextAttribute::FontSize(18.0)) .build()?; - let y_pos = ((SIZE.height - layout.size().height * 2.0) / 4.0).max(0.0); + let y_pos = ((SIZE.height - layout.size().height) / 2.0).max(0.0); let text_pos = Vec2::new(16.0, y_pos); let sel_one = layout.rects_for_range(10..72); diff --git a/piet/src/samples/picture_13.rs b/piet/src/samples/picture_13.rs index 1750fdf6..c3815a96 100644 --- a/piet/src/samples/picture_13.rs +++ b/piet/src/samples/picture_13.rs @@ -6,7 +6,7 @@ use crate::{ TextLayoutBuilder, }; -pub const SIZE: Size = Size::new(480., 560.); +pub const SIZE: Size = Size::new(240., 280.); static TEXT: &str = r#"Philosophers often behave like little children who scribble some marks on a piece of paper at random and then ask the grown-up "What's that?" — It happened like this: the grown-up had drawn pictures for the child several times and said "this is a man," "this is a house," etc. And then the child makes some marks too and asks: what's this then?"#; @@ -35,7 +35,7 @@ pub fn draw(rc: &mut R) -> Result<(), Error> { .range_attribute(250..320, FontWeight::EXTRA_LIGHT) .build()?; - let y_pos = ((SIZE.height - layout.size().height * 2.0) / 4.0).max(0.0); + let y_pos = ((SIZE.height - layout.size().height) / 2.0).max(0.0); let text_pos = Vec2::new(16.0, y_pos); rc.draw_text(&layout, text_pos.to_point()); diff --git a/piet/src/samples/picture_14.rs b/piet/src/samples/picture_14.rs index 297b1e48..90392ed6 100644 --- a/piet/src/samples/picture_14.rs +++ b/piet/src/samples/picture_14.rs @@ -5,7 +5,7 @@ use crate::{ Color, Error, FontFamily, FontWeight, RenderContext, Text, TextLayout, TextLayoutBuilder, }; -pub const SIZE: Size = Size::new(480., 560.); +pub const SIZE: Size = Size::new(240., 280.); static TEXT: &str = r#"100200300400500 600700800900950"#; @@ -35,7 +35,7 @@ pub fn draw(rc: &mut R) -> Result<(), Error> { .range_attribute(28..31, FontWeight::EXTRA_BLACK) .build()?; - let y_pos = ((SIZE.height - layout.size().height * 2.0) / 4.0).max(0.0); + let y_pos = ((SIZE.height - layout.size().height) / 2.0).max(0.0); let text_pos = Vec2::new(16.0, y_pos); rc.draw_text(&layout, text_pos.to_point()); diff --git a/piet/src/samples/picture_15.rs b/piet/src/samples/picture_15.rs index 337beb0a..8bd739e8 100644 --- a/piet/src/samples/picture_15.rs +++ b/piet/src/samples/picture_15.rs @@ -7,7 +7,7 @@ use crate::kurbo::{Affine, Circle, Rect, Size}; use crate::{Color, Error, RenderContext}; -pub const SIZE: Size = Size::new(400., 400.); +pub const SIZE: Size = Size::new(200., 200.); const RED: Color = Color::rgb8(255, 0, 0); const BLUE: Color = Color::rgb8(0, 0, 255); diff --git a/piet/src/samples/picture_2.rs b/piet/src/samples/picture_2.rs index 3309f5d9..1577b8d3 100644 --- a/piet/src/samples/picture_2.rs +++ b/piet/src/samples/picture_2.rs @@ -3,7 +3,7 @@ use crate::kurbo::{Rect, Size}; use crate::{Color, Error, ImageFormat, InterpolationMode, RenderContext}; -pub const SIZE: Size = Size::new(400., 200.); +pub const SIZE: Size = Size::new(200., 100.); pub fn draw(rc: &mut impl RenderContext) -> Result<(), Error> { rc.clear(None, Color::WHITE); diff --git a/piet/src/samples/picture_3.rs b/piet/src/samples/picture_3.rs index 7d8c4431..c9ddb0d6 100644 --- a/piet/src/samples/picture_3.rs +++ b/piet/src/samples/picture_3.rs @@ -3,7 +3,7 @@ use crate::kurbo::{Affine, BezPath, Line, Size}; use crate::{Color, Error, LineCap, LineJoin, RenderContext, StrokeStyle}; -pub const SIZE: Size = Size::new(400., 200.); +pub const SIZE: Size = Size::new(200., 100.); pub fn draw(rc: &mut R) -> Result<(), Error> { rc.clear(None, Color::WHITE); diff --git a/piet/src/samples/picture_4.rs b/piet/src/samples/picture_4.rs index 6c16c538..4787a68f 100644 --- a/piet/src/samples/picture_4.rs +++ b/piet/src/samples/picture_4.rs @@ -6,7 +6,7 @@ use crate::{ RenderContext, }; -pub const SIZE: Size = Size::new(400., 200.); +pub const SIZE: Size = Size::new(200., 100.); pub fn draw(rc: &mut R) -> Result<(), Error> { rc.clear(None, Color::WHITE); diff --git a/piet/src/samples/picture_5.rs b/piet/src/samples/picture_5.rs index 2c7f5ad9..5bbdb06c 100644 --- a/piet/src/samples/picture_5.rs +++ b/piet/src/samples/picture_5.rs @@ -6,7 +6,7 @@ use crate::{ TextLayout, TextLayoutBuilder, }; -pub const SIZE: Size = Size::new(480., 560.); +pub const SIZE: Size = Size::new(240., 280.); static TEXT: &str = r#"Philosophers often behave like little children who scribble some marks on a piece of paper at random and then ask the grown-up "What's that?" — It happened like this: the grown-up had drawn pictures for the child several times and said "this is a man," "this is a house," etc. And then the child makes some marks too and asks: what's this then?"#; @@ -36,7 +36,7 @@ pub fn draw(rc: &mut R) -> Result<(), Error> { .range_attribute(240.., FontFamily::SYSTEM_UI) .build()?; - let y_pos = ((SIZE.height - layout.size().height * 2.0) / 4.0).max(0.0); + let y_pos = ((SIZE.height - layout.size().height) / 2.0).max(0.0); let text_pos = Vec2::new(16.0, y_pos); rc.draw_text(&layout, text_pos.to_point()); diff --git a/piet/src/samples/picture_6.rs b/piet/src/samples/picture_6.rs index 59f05221..6c9f7db8 100644 --- a/piet/src/samples/picture_6.rs +++ b/piet/src/samples/picture_6.rs @@ -6,7 +6,7 @@ use crate::{ LineJoin, RenderContext, StrokeStyle, }; -pub const SIZE: Size = Size::new(400., 200.); +pub const SIZE: Size = Size::new(200., 100.); pub fn draw(rc: &mut R) -> Result<(), Error> { rc.clear(None, Color::BLACK); diff --git a/piet/src/samples/picture_7.rs b/piet/src/samples/picture_7.rs index 168c3a38..d0e3d32e 100644 --- a/piet/src/samples/picture_7.rs +++ b/piet/src/samples/picture_7.rs @@ -3,7 +3,7 @@ use crate::kurbo::{Rect, Size}; use crate::{Color, Error, RenderContext, Text, TextAlignment, TextAttribute, TextLayoutBuilder}; -pub const SIZE: Size = Size::new(800., 800.); +pub const SIZE: Size = Size::new(400., 400.); static SAMPLE_EN: &str = r#"This essay is an effort to build an ironic political myth faithful to feminism, socialism, and materialism. Perhaps more faithful as blasphemy is faithful, than as reverent worship and identification. Blasphemy has always seemed to require taking things very seriously. I know no better stance to adopt from within the secular-religious, evangelical traditions of United States politics, including the politics of socialist-feminism."#; static SAMPLE_AR: &str = r#"لكن لا بد أن أوضح لك أن كل هذه الأفكار المغلوطة حول استنكار النشوة وتمجيد الألم نشأت بالفعل، وسأعرض لك التفاصيل لتكتشف حقيقة وأساس تلك السعادة البشرية، فلا أحد يرفض أو يكره أو يتجنب الشعور بالسعادة، ولكن بفضل هؤلاء الأشخاص الذين لا يدركون بأن السعادة لا بد أن نستشعرها بصورة أكثر عقلانية ومنطقية فيعرضهم هذا لمواجهة الظروف الأليمة، وأكرر بأنه لا يوجد من يرغب في الحب ونيل المنال ويتلذذ بالآلام، الألم هو الألم ولكن نتيجة لظروف ما قد تكمن السعاده فيما نتحمله من كد وأسي."#; diff --git a/piet/src/samples/picture_8.rs b/piet/src/samples/picture_8.rs index 94fef9b5..fb0d3a2b 100644 --- a/piet/src/samples/picture_8.rs +++ b/piet/src/samples/picture_8.rs @@ -6,7 +6,7 @@ use crate::{ TextAttribute, TextLayoutBuilder, }; -pub const SIZE: Size = Size::new(400., 800.); +pub const SIZE: Size = Size::new(200., 400.); static SAMPLE_EN: &str = r#"This essay is an effort to build an ironic political myth faithful to feminism, socialism, and materialism. Perhaps more faithful as blasphemy is faithful, than as reverent worship and identification. Blasphemy has always seemed to require taking things very seriously. I know no better stance to adopt from within the secular-religious, evangelical traditions of United States politics, including the politics of socialist-feminism."#; diff --git a/piet/src/samples/picture_9.rs b/piet/src/samples/picture_9.rs index 171cef27..81eed917 100644 --- a/piet/src/samples/picture_9.rs +++ b/piet/src/samples/picture_9.rs @@ -6,7 +6,7 @@ use crate::{ TextLayoutBuilder, }; -pub const SIZE: Size = Size::new(464., 800.); +pub const SIZE: Size = Size::new(232., 400.); static SAMPLE_EN: &str = r#"1nnyyÊbbbb soft break 2nnyyÊbbbb