From 9fe39951b07c2bcb0aebf7909719b150dcf5c973 Mon Sep 17 00:00:00 2001 From: Gilles Leblanc Date: Wed, 7 Jan 2015 21:07:23 -0500 Subject: [PATCH] Write a macro or syntax extension to generate OpenType tags Fixes #4556 --- components/gfx/text/shaping/harfbuzz.rs | 12 ++++++++---- components/gfx/text/util.rs | 14 -------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index c86336b2ec6f..cc328ca4f8c8 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -47,13 +47,17 @@ use std::mem; use std::cmp; use std::ptr; +macro_rules! hb_tag { + ($t1:expr, $t2:expr, $t3:expr, $t4:expr) => ( + (($t1 as u32) << 24) | (($t2 as u32) << 16) | (($t3 as u32) << 8) | ($t4 as u32) + ); +} + static NO_GLYPH: i32 = -1; static CONTINUATION_BYTE: i32 = -2; -static KERN: u32 = ((b'k' as u32) << 24) | ((b'e' as u32) << 16) | ((b'r' as u32) << 8) | - (b'n' as u32); -static LIGA: u32 = ((b'l' as u32) << 24) | ((b'i' as u32) << 16) | ((b'g' as u32) << 8) | - (b'a' as u32); +static KERN: u32 = hb_tag!('k', 'e', 'r', 'n'); +static LIGA: u32 = hb_tag!('l', 'i', 'g', 'a'); pub struct ShapedGlyphData { count: int, diff --git a/components/gfx/text/util.rs b/components/gfx/text/util.rs index c8d082c405a5..24c916a1ba1f 100644 --- a/components/gfx/text/util.rs +++ b/components/gfx/text/util.rs @@ -128,20 +128,6 @@ pub fn fixed_to_rounded_int(before: int, f: i32) -> int { } } -/* Generate a 32-bit TrueType tag from its 4 characters */ -pub fn true_type_tag(a: char, b: char, c: char, d: char) -> u32 { - let a = a as u32; - let b = b as u32; - let c = c as u32; - let d = d as u32; - (a << 24 | b << 16 | c << 8 | d) as u32 -} - -#[test] -fn test_true_type_tag() { - assert_eq!(true_type_tag('c', 'm', 'a', 'p'), 0x_63_6D_61_70_u32); -} - #[test] fn test_transform_compress_none() { let test_strs = [