From: Ben Pfaff Date: Mon, 21 Apr 2025 01:48:46 +0000 (-0700) Subject: Break up cairo module. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dba8c0de56e07aa4d21538fba7ad3c40df01004;p=pspp Break up cairo module. --- diff --git a/rust/pspp/src/output/cairo.rs b/rust/pspp/src/output/cairo.rs deleted file mode 100644 index b6cdeb922f..0000000000 --- a/rust/pspp/src/output/cairo.rs +++ /dev/null @@ -1,743 +0,0 @@ -use std::{ - borrow::Cow, cmp::min, f64::consts::PI, fmt::Write, ops::DerefMut, path::Path, sync::Arc, -}; - -use cairo::{Context, PdfSurface, Surface}; -use enum_map::{enum_map, EnumMap}; -use itertools::Itertools; -use pango::{ - parse_markup, AttrFloat, AttrFontDesc, AttrInt, AttrList, Attribute, FontDescription, FontMask, - Layout, Underline, Weight, SCALE, SCALE_SMALL, -}; -use pangocairo::functions::show_layout; -use smallvec::{smallvec, SmallVec}; - -use crate::output::{ - driver::Driver, - page::Setup, - pivot::{Color, Coord2, FontStyle, HorzAlign, Stroke}, - render::{Device, DrawCell, Extreme, Params}, - table::Content, - Item, -}; - -use super::pivot::{Axis2, BorderStyle, Rect2}; - -/// Width of an ordinary line. -const LINE_WIDTH: usize = LINE_SPACE / 2; - -/// Space between double lines. -const LINE_SPACE: usize = SCALE as usize; - -/// Conversion from 1/96" units ("pixels") to Cairo/Pango units. -fn px_to_xr(x: usize) -> usize { - x * 3 * (SCALE as usize * 72 / 96) / 3 -} - -fn xr_to_pt(x: usize) -> f64 { - x as f64 / SCALE as f64 -} - -fn xr_to_pango(x: usize) -> usize { - x -} - -/// Conversion from 1/96" units ("pixels") to Cairo/Pango units. -fn pxf_to_xr(x: f64) -> usize { - (x * (SCALE as f64 * 72.0 / 96.0)).round() as usize -} - -pub struct Style { - /// Page size. - pub size: Coord2, - - /// Minimum cell size to allow breaking. - pub min_break: EnumMap, - - /// The basic font. - pub font: FontDescription, - - /// Foreground color. - pub fg: Color, - - /// Use system colors? - pub use_system_colors: bool, - - /// Vertical space between different output items. - pub object_spacing: usize, - - /// Resolution, in units per inch, used for measuring font "points": - /// - /// - 72.0 if 1 pt is one device unit, e.g. for rendering to a surface - /// created by [PsSurface::new] with its default transformation matrix of 72 - /// units/inch.p - /// - /// - 96.0 is traditional for a screen-based surface. - pub font_resolution: f64, -} - -impl Style { - fn new_layout(&self, context: &Context) -> Layout { - let pangocairo_context = pangocairo::functions::create_context(context); - pangocairo::functions::context_set_resolution(&pangocairo_context, self.font_resolution); - Layout::new(&pangocairo_context) - } -} - -pub struct CairoRenderer { - style: Arc