pub fn drawing_with_text_as_paths<InStream: 'static+Send+Unpin+Stream<Item=Draw>>(draw_stream: InStream) -> impl Send+Unpin+Stream<Item=Draw> {
    generator_stream(move |yield_value| async move {
        // Set up
        let mut draw_stream = draw_stream;
        let mut font_map    = HashMap::new();

        // Pass through the drawing instructions, and process any font instructions that we may come across
        while let Some(draw) = draw_stream.next().await {
            match draw {
                Draw::ClearCanvas(_) => {
                    font_map.clear();

                    yield_value(draw).await;
                }

                Draw::Font(font_id, FontOp::UseFontDefinition(data)) => {
                    // Store the font to use for this ID
                    font_map.insert(font_id, Arc::clone(&data));
                    yield_value(Draw::Font(font_id, FontOp::UseFontDefinition(data))).await;
                }

                Draw::Font(font_id, FontOp::DrawGlyphs(glyphs)) => {
                    if let Some(font) = font_map.get(&font_id) {
                        // Use this font to generate the glyphs
                        let ttf_font        = font.ttf_font();
                        let units_per_em    = ttf_font.units_per_em().unwrap_or(16385) as f32;

                        for glyph in glyphs {
                            // Start rendering this glyph
                            yield_value(Draw::Path(PathOp::NewPath)).await;

                            let GlyphId(glyph_id)   = glyph.id;
                            let glyph_id            = ttf_parser::GlyphId(glyph_id as _);

                            // Generate the outline
                            let mut drawing         = vec![];
                            let mut outliner        = FontOutliner { 
                                drawing:        &mut drawing,
                                scale_factor:   glyph.em_size / units_per_em,
                                x_pos:          glyph.location.0,
                                y_pos:          glyph.location.1,
                                last:           (0.0, 0.0)
                            };

                            ttf_font.outline_glyph(glyph_id, &mut outliner);

                            // Render the drawing
                            for draw in drawing {
                                yield_value(draw).await;
                            }

                            // Fill the path
                            yield_value(Draw::Fill).await;
                        }
                    }
                }

                _ => {
                    // Send non-text instructions through as-is
                    yield_value(draw).await;
                }
            }
        }
    })
}
///
/// Given a stream of drawing instructions (such as is returned by `Canvas::stream()`), turns any glyph drawing instructions 
/// into the equivalent path drawing instructions.
///
/// Along with `drawing_with_laid_out_text`, this can be used to render text to a render target that does not have any font 
/// support of its own.
///
Given a stream of drawing instructions (such as is returned by `Canvas::stream()`), turns any glyph drawing instructions
into the equivalent path drawing instructions.

Along with `drawing_with_laid_out_text`, this can be used to render text to a render target that does not have any font
support of its own.
Given a stream of drawing instructions ( such as is returned by ` Canvas :: stream () ` ) turns any glyph drawing instructions into the equivalent path drawing instructions . Along with ` drawing_with_laid_out_text ` this can be used to render text to a render target that does not have any font support of its own .
pub fn drawing_with_text_as_paths<InStream: 'static+Send+Unpin+Stream<Item=Draw>>(draw_stream: InStream) -> impl Send+Unpin+Stream<Item=Draw> {
    generator_stream(move |yield_value| async move {
        // Set up
        let mut draw_stream = draw_stream;
        let mut font_map    = HashMap::new();
        // Pass through the drawing instructions, and process any font instructions that we may come across
        while let Some(draw) = draw_stream.next().await {
            match draw {
                Draw::ClearCanvas(_) => {
                    font_map.clear();
                    yield_value(draw).await;
                }
                Draw::Font(font_id, FontOp::UseFontDefinition(data)) => {
                    // Store the font to use for this ID
                    font_map.insert(font_id, Arc::clone(&data));
                    yield_value(Draw::Font(font_id, FontOp::UseFontDefinition(data))).await;
                }
                Draw::Font(font_id, FontOp::DrawGlyphs(glyphs)) => {
                    if let Some(font) = font_map.get(&font_id) {
                        // Use this font to generate the glyphs
                        let ttf_font        = font.ttf_font();
                        let units_per_em    = ttf_font.units_per_em().unwrap_or(16385) as f32;
                        for glyph in glyphs {
                            // Start rendering this glyph
                            yield_value(Draw::Path(PathOp::NewPath)).await;
                            let GlyphId(glyph_id)   = glyph.id;
                            let glyph_id            = ttf_parser::GlyphId(glyph_id as _);
                            // Generate the outline
                            let mut drawing         = vec![];
                            let mut outliner        = FontOutliner { 
                                drawing:        &mut drawing,
                                scale_factor:   glyph.em_size / units_per_em,
                                x_pos:          glyph.location.0,
                                y_pos:          glyph.location.1,
                                last:           (0.0, 0.0)
                            };
                            ttf_font.outline_glyph(glyph_id, &mut outliner);
                            // Render the drawing
                            for draw in drawing {
                                yield_value(draw).await;
                            }
                            // Fill the path
                            yield_value(Draw::Fill).await;
                        }
                    }
                }
                _ => {
                    // Send non-text instructions through as-is
                    yield_value(draw).await;
                }
            }
        }
    })
}
pub fn drawing_with_text_as_paths < InStream : ' static + Send + Unpin + Stream < Item = Draw > > ( draw_stream : InStream ) -> impl Send + Unpin + Stream < Item = Draw > { generator_stream ( move | yield_value | async move { // Set up let mut draw_stream = draw_stream ; let mut font_map = HashMap :: new ( ) ; // Pass through the drawing instructions, and process any font instructions that we may come across while let Some ( draw ) = draw_stream . next ( ) . await { match draw { Draw :: ClearCanvas ( _ ) => { font_map . clear ( ) ; yield_value ( draw ) . await ; } Draw :: Font ( font_id , FontOp :: UseFontDefinition ( data ) ) => { // Store the font to use for this ID font_map . insert ( font_id , Arc :: clone ( & data ) ) ; yield_value ( Draw :: Font ( font_id , FontOp :: UseFontDefinition ( data ) ) ) . await ; } Draw :: Font ( font_id , FontOp :: DrawGlyphs ( glyphs ) ) => { if let Some ( font ) = font_map . get ( & font_id ) { // Use this font to generate the glyphs let ttf_font = font . ttf_font ( ) ; let units_per_em = ttf_font . units_per_em ( ) . unwrap_or ( 16385 ) as f32 ; for glyph in glyphs { // Start rendering this glyph yield_value ( Draw :: Path ( PathOp :: NewPath ) ) . await ; let GlyphId ( glyph_id ) = glyph . id ; let glyph_id = ttf_parser :: GlyphId ( glyph_id as _ ) ; // Generate the outline let mut drawing = vec ! [ ] ; let mut outliner = FontOutliner { drawing : & mut drawing , scale_factor : glyph . em_size / units_per_em , x_pos : glyph . location . 0 , y_pos : glyph . location . 1 , last : ( 0.0 , 0.0 ) } ; ttf_font . outline_glyph ( glyph_id , & mut outliner ) ; // Render the drawing for draw in drawing { yield_value ( draw ) . await ; } // Fill the path yield_value ( Draw :: Fill ) . await ; } } } _ => { // Send non-text instructions through as-is yield_value ( draw ) . await ; } } } } ) }
Given a stream of drawing instructions (such as is returned by `Canvas::stream()`), turns any glyph drawing instructions
into the equivalent path drawing instructions.
Given a stream of drawing instructions ( such as is returned by ` Canvas :: stream () ` ) turns any glyph drawing instructions into the equivalent path drawing instructions .
draw_stream
InStream