use super::{FontMetrics, Glyph};
pub const FONT_CHICAGO: i16 = 0;
pub const FONT_APPLICATION: i16 = 1; pub const FONT_NEWYORK: i16 = 2;
pub const FONT_GENEVA: i16 = 3;
pub const FONT_MONACO: i16 = 4;
pub const FONT_VENICE: i16 = 5;
pub const FONT_LONDON: i16 = 6;
pub const FONT_ATHENS: i16 = 7;
pub const FONT_SANFRAN: i16 = 8;
pub const FONT_TORONTO: i16 = 9;
pub const FONT_SEATTLE: i16 = 10;
pub const FONT_CAIRO: i16 = 11;
pub const FONT_LOSANGELES: i16 = 12;
pub const FONT_TIMES: i16 = 20;
pub const FONT_HELVETICA: i16 = 21;
pub const FONT_COURIER: i16 = 22;
pub const FONT_SYMBOL: i16 = 23;
pub const FONT_MOBILE: i16 = 24;
pub fn get_italic_slant(
font_id: i16,
size: i16,
metrics: &FontMetrics,
baseline_y: i16,
curr_y: i16,
) -> i16 {
if font_id == FONT_GENEVA && size == 9 {
let dy = curr_y - baseline_y;
return match dy {
-10..=-5 => 1, _ => 0,
};
}
if font_id == FONT_CHICAGO && size == 9 {
let dy = curr_y - baseline_y;
return match dy {
..=-6 => 2,
-5..=-3 => 1,
_ => 0,
};
}
if font_id == FONT_MONACO && size == 10 {
let dy = curr_y - baseline_y;
return match dy {
..=-8 => 3,
-7..=-6 => 2,
-5..=-3 => 1,
_ => 0,
};
}
let font_height = metrics.ascent + metrics.descent;
let font_top = baseline_y - metrics.ascent;
let row = (curr_y - font_top).max(0);
if font_height % 2 == 0 {
let shift = if row == 0 { 0 } else { (row / 2) + 1 };
(font_height / 2 - shift).max(0)
} else {
let dy = ((baseline_y + metrics.descent - 1) - curr_y).max(0);
dy / 2
}
}
pub fn get_italic_slant_for_underline(
font_id: i16,
size: i16,
metrics: &FontMetrics,
baseline_y: i16,
check_y: i16,
) -> i16 {
if font_id == FONT_GENEVA && size == 9 {
let font_height = 7i16;
let font_top = baseline_y - metrics.ascent;
let row = (check_y - font_top).max(0);
let shift_count = (row + 1) / 2;
return (font_height / 2 - shift_count).max(0);
}
let font_bottom = baseline_y + metrics.descent;
let dy = ((font_bottom - 1) - check_y).max(0);
dy / 2
}
pub fn get_italic_underline_extend_left(
font_id: i16,
size: i16,
is_bold: bool,
use_precaptured_italic: bool,
) -> i16 {
if font_id == FONT_GENEVA && size == 24 {
return 3;
}
if font_id == FONT_GENEVA && size == 9 && use_precaptured_italic {
return 2;
}
let base = if size >= 18 { 2 } else { 1 };
if is_bold && size == 14 && font_id == FONT_GENEVA {
return base + 1;
}
if is_bold && size == 14 && font_id == FONT_VENICE {
return base + 1;
}
base
}
pub fn get_italic_underline_extend_right(font_id: i16, size: i16) -> i16 {
if font_id == FONT_GENEVA && size == 24 {
return 4;
}
0
}
pub fn get_underline_offset(font_id: i16, size: i16, glyph: &Glyph, is_shadow: bool) -> i16 {
let mut off = 0;
if font_id == FONT_GENEVA && size == 24
&& glyph.origin_x <= 0 {
off -= 1;
}
if is_shadow {
off -= 1;
}
off
}
pub fn get_italic_end_extend(font_id: i16, size: i16, metrics: &FontMetrics) -> i16 {
let base = if size <= 10 {
(metrics.ascent / 2 - 1).max(0)
} else {
(metrics.descent / 2 + 2).max(4) + 1 };
match size {
14 => base + 1,
18 => base + 3, 9 if font_id == FONT_MONACO => base + 1, _ => base,
}
}
pub fn use_smart_underline_break(font_id: i16, size: i16) -> bool {
size == 18 || (font_id == FONT_GENEVA && size == 24)
}
pub fn use_baseline_analysis(font_id: i16, size: i16) -> bool {
font_id == FONT_NEWYORK && size == 18
}