fn decode(mut self, chr: char) -> Result<DecodeGlyphPositions, DecoderError> {
        // Decode or fetch the length of the string
        let length = match self.length {
            PartialResult::MatchMore(so_far)    => {
                self.length = CanvasDecoder::decode_compact_id(chr, so_far)?;

                if let &PartialResult::FullMatch(0) = &self.length {
                    self.glyphs = PartialResult::FullMatch(vec![]);
                }
                return Ok(self);
            }

            PartialResult::FullMatch(length)    => {
                self.length = PartialResult::FullMatch(length);
                length as usize
            }
        };

        // Try to decode the rest of the string
        match self.glyphs {
            PartialResult::FullMatch(glyphs)    => {
                // Nothing to do
                self.glyphs = PartialResult::FullMatch(glyphs);
            }

            PartialResult::MatchMore(mut string)    => {
                string.push(chr);

                if string.len() >= length * 24 {
                    let mut chrs    = string.chars();
                    let mut glyphs  = vec![];

                    // Each glyph consists of a glyph ID, an x and y coord and a em_size
                    for _ in 0..length {
                        let id      = CanvasDecoder::decode_u32(&mut chrs)?;
                        let x       = CanvasDecoder::decode_f32(&mut chrs)?;
                        let y       = CanvasDecoder::decode_f32(&mut chrs)?;
                        let em_size = CanvasDecoder::decode_f32(&mut chrs)?;

                        glyphs.push(GlyphPosition {
                            id:         GlyphId(id),
                            location:   (x, y),
                            em_size:    em_size
                        });
                    }

                    self.glyphs = PartialResult::FullMatch(glyphs);
                } else {
                    self.glyphs = PartialResult::MatchMore(string);
                }
            }
        }

        Ok(self)
    }
///
/// Decodes a single character and returns the new state of the decoder
///
Decodes a single character and returns the new state of the decoder
Decodes a single character and returns the new state of the decoder
fn decode(mut self, chr: char) -> Result<DecodeGlyphPositions, DecoderError> {
        // Decode or fetch the length of the string
        let length = match self.length {
            PartialResult::MatchMore(so_far)    => {
                self.length = CanvasDecoder::decode_compact_id(chr, so_far)?;
                if let &PartialResult::FullMatch(0) = &self.length {
                    self.glyphs = PartialResult::FullMatch(vec![]);
                }
                return Ok(self);
            }
            PartialResult::FullMatch(length)    => {
                self.length = PartialResult::FullMatch(length);
                length as usize
            }
        };
        // Try to decode the rest of the string
        match self.glyphs {
            PartialResult::FullMatch(glyphs)    => {
                // Nothing to do
                self.glyphs = PartialResult::FullMatch(glyphs);
            }
            PartialResult::MatchMore(mut string)    => {
                string.push(chr);
                if string.len() >= length * 24 {
                    let mut chrs    = string.chars();
                    let mut glyphs  = vec![];
                    // Each glyph consists of a glyph ID, an x and y coord and a em_size
                    for _ in 0..length {
                        let id      = CanvasDecoder::decode_u32(&mut chrs)?;
                        let x       = CanvasDecoder::decode_f32(&mut chrs)?;
                        let y       = CanvasDecoder::decode_f32(&mut chrs)?;
                        let em_size = CanvasDecoder::decode_f32(&mut chrs)?;
                        glyphs.push(GlyphPosition {
                            id:         GlyphId(id),
                            location:   (x, y),
                            em_size:    em_size
                        });
                    }
                    self.glyphs = PartialResult::FullMatch(glyphs);
                } else {
                    self.glyphs = PartialResult::MatchMore(string);
                }
            }
        }
        Ok(self)
    }
fn decode ( mut self , chr : char ) -> Result < DecodeGlyphPositions , DecoderError > { // Decode or fetch the length of the string let length = match self . length { PartialResult :: MatchMore ( so_far ) => { self . length = CanvasDecoder :: decode_compact_id ( chr , so_far ) ? ; if let & PartialResult :: FullMatch ( 0 ) = & self . length { self . glyphs = PartialResult :: FullMatch ( vec ! [ ] ) ; } return Ok ( self ) ; } PartialResult :: FullMatch ( length ) => { self . length = PartialResult :: FullMatch ( length ) ; length as usize } } ; // Try to decode the rest of the string match self . glyphs { PartialResult :: FullMatch ( glyphs ) => { // Nothing to do self . glyphs = PartialResult :: FullMatch ( glyphs ) ; } PartialResult :: MatchMore ( mut string ) => { string . push ( chr ) ; if string . len ( ) >= length * 24 { let mut chrs = string . chars ( ) ; let mut glyphs = vec ! [ ] ; // Each glyph consists of a glyph ID, an x and y coord and a em_size for _ in 0 .. length { let id = CanvasDecoder :: decode_u32 ( & mut chrs ) ? ; let x = CanvasDecoder :: decode_f32 ( & mut chrs ) ? ; let y = CanvasDecoder :: decode_f32 ( & mut chrs ) ? ; let em_size = CanvasDecoder :: decode_f32 ( & mut chrs ) ? ; glyphs . push ( GlyphPosition { id : GlyphId ( id ) , location : ( x , y ) , em_size : em_size } ) ; } self . glyphs = PartialResult :: FullMatch ( glyphs ) ; } else { self . glyphs = PartialResult :: MatchMore ( string ) ; } } } Ok ( self ) }
Decodes a single character and returns the new state of the decoder
Decodes a single character and returns the new state of the decoder
mut self
chr
char