@@ -13,43 +13,45 @@ use crate::tests::{
13
13
use crate :: util:: SliceExt ;
14
14
use crate :: Fill ;
15
15
use rustybuzz:: Direction ;
16
- use skrifa:: instance:: Location ;
17
- use skrifa:: GlyphId ;
16
+ use skrifa:: instance:: { Location , LocationRef , Size } ;
17
+ use skrifa:: { GlyphId , MetadataProvider } ;
18
18
use std:: sync:: Arc ;
19
+ use skrifa:: raw:: TableProvider ;
19
20
21
+ #[ ignore]
20
22
#[ test]
21
23
fn simple_shape_demo ( ) {
22
24
let mut y = 25.0 ;
23
25
24
26
let data = vec ! [
25
27
(
26
- NOTO_SANS_ARABIC ,
28
+ NOTO_SANS_ARABIC . clone ( ) ,
27
29
"هذا نص أطول لتجربة القدرات." ,
28
30
Direction :: RightToLeft ,
29
31
14.0 ,
30
32
) ,
31
33
(
32
- NOTO_SANS ,
34
+ NOTO_SANS . clone ( ) ,
33
35
"Hi there, this is a very simple test!" ,
34
36
Direction :: LeftToRight ,
35
37
14.0 ,
36
38
) ,
37
39
(
38
- DEJAVU_SANS_MONO ,
40
+ DEJAVU_SANS_MONO . clone ( ) ,
39
41
"Here with a mono font, some longer text." ,
40
42
Direction :: LeftToRight ,
41
43
16.0 ,
42
44
) ,
43
- ( NOTO_SANS , "z͈̤̭͖̉͑́a̳ͫ́̇͑̽͒ͯlͨ͗̍̀̍̔̀ģ͔̫̫̄o̗̠͔̦̳͆̏̓͢" , Direction :: LeftToRight , 14.0 ) ,
44
- ( NOTO_SANS , " birth\u{ad} day " , Direction :: LeftToRight , 14.0 ) ,
45
+ ( NOTO_SANS . clone ( ) , "z͈̤̭͖̉͑́a̳ͫ́̇͑̽͒ͯlͨ͗̍̀̍̔̀ģ͔̫̫̄o̗̠͔̦̳͆̏̓͢" , Direction :: LeftToRight , 14.0 ) ,
46
+ ( NOTO_SANS . clone ( ) , " birth\u{ad} day " , Direction :: LeftToRight , 14.0 ) ,
45
47
(
46
- NOTO_SANS_CJK ,
48
+ NOTO_SANS_CJK . clone ( ) ,
47
49
"你好世界,这是一段很长的测试文章" ,
48
50
Direction :: LeftToRight ,
49
51
14.0 ,
50
52
) ,
51
53
(
52
- NOTO_SANS_DEVANAGARI ,
54
+ NOTO_SANS_DEVANAGARI . clone ( ) ,
53
55
"आ रु॒क्मैरा यु॒धा नर॑ ऋ॒ष्वा ऋ॒ष्टीर॑सृक्षत ।" ,
54
56
Direction :: LeftToRight ,
55
57
14.0 ,
@@ -137,3 +139,86 @@ fn cosmic_text_integration() {
137
139
let pdf = document_builder. finish ( ) ;
138
140
write_manual_to_store ( "cosmic_text" , & pdf) ;
139
141
}
142
+
143
+ #[ ignore]
144
+ #[ test]
145
+ fn svg_twitter ( ) {
146
+ let font_data = std:: fs:: read ( "/Library/Fonts/TwitterColorEmoji-SVGinOT.ttf" ) . unwrap ( ) ;
147
+ all_glyphs_to_pdf ( Arc :: new ( font_data) , None , "svg_twitter" ) ;
148
+ }
149
+
150
+ fn all_glyphs_to_pdf ( font_data : Arc < Vec < u8 > > , glyphs : Option < Vec < ( GlyphId , String ) > > , name : & str ) {
151
+ use crate :: document:: Document ;
152
+ use crate :: object:: color_space:: rgb:: Rgb ;
153
+ use crate :: serialize:: SerializeSettings ;
154
+ use crate :: stream:: Glyph ;
155
+ use crate :: Transform ;
156
+
157
+ let font = Font :: new ( font_data, 0 , Location :: default ( ) ) . unwrap ( ) ;
158
+ let font_ref = font. font_ref ( ) ;
159
+
160
+ let glyphs = glyphs. unwrap_or_else ( || {
161
+ let file =
162
+ std:: fs:: read ( "/Users/lstampfl/Programming/GitHub/krilla/src/font/emojis.txt" ) . unwrap ( ) ;
163
+ let file = std:: str:: from_utf8 ( & file) . unwrap ( ) ;
164
+ file. chars ( )
165
+ . filter_map ( |c| {
166
+ font_ref
167
+ . cmap ( )
168
+ . unwrap ( )
169
+ . map_codepoint ( c)
170
+ . map ( |g| ( g, c. to_string ( ) ) )
171
+ } )
172
+ . collect :: < Vec < _ > > ( )
173
+ } ) ;
174
+
175
+ let metrics = font_ref. metrics ( Size :: unscaled ( ) , LocationRef :: default ( ) ) ;
176
+ let num_glyphs = glyphs. len ( ) ;
177
+ let width = 400 ;
178
+
179
+ let size = 40u32 ;
180
+ let num_cols = width / size;
181
+ let height = ( num_glyphs as f32 / num_cols as f32 ) . ceil ( ) as u32 * size;
182
+ let units_per_em = metrics. units_per_em as f32 ;
183
+ let mut cur_point = 0 ;
184
+
185
+ let page_size = tiny_skia_path:: Size :: from_wh ( width as f32 , height as f32 ) . unwrap ( ) ;
186
+ let mut document_builder = Document :: new ( SerializeSettings :: default ( ) ) ;
187
+ let mut builder = document_builder. start_page ( page_size) ;
188
+ let mut surface = builder. surface ( ) ;
189
+
190
+ for ( i, text) in glyphs. iter ( ) . cloned ( ) {
191
+ fn get_transform ( cur_point : u32 , size : u32 , num_cols : u32 , _: f32 ) -> Transform {
192
+ let el = cur_point / size;
193
+ let col = el % num_cols;
194
+ let row = el / num_cols;
195
+
196
+ Transform :: from_row (
197
+ 1.0 ,
198
+ 0.0 ,
199
+ 0.0 ,
200
+ 1.0 ,
201
+ col as f32 * size as f32 ,
202
+ ( row + 1 ) as f32 * size as f32 ,
203
+ )
204
+ }
205
+
206
+ surface. push_transform ( & get_transform ( cur_point, size, num_cols, units_per_em) ) ;
207
+ surface. draw_glyph_run (
208
+ 0.0 ,
209
+ 0.0 ,
210
+ crate :: Fill :: < Rgb > :: default ( ) ,
211
+ & [ Glyph :: new ( i, 0.0 , 0.0 , 0.0 , 0 ..text. len ( ) , size as f32 ) ] ,
212
+ font. clone ( ) ,
213
+ & text,
214
+ ) ;
215
+ surface. pop ( ) ;
216
+
217
+ cur_point += size;
218
+ }
219
+
220
+ surface. finish ( ) ;
221
+ builder. finish ( ) ;
222
+ let pdf = document_builder. finish ( ) ;
223
+ write_manual_to_store ( name, & pdf) ;
224
+ }
0 commit comments