| 64 | } |
| 65 | |
| 66 | bool FontSprite::loadFromStream( IOStream& stream, Color key, Uint32 firstChar, int spacing ) { |
| 67 | if ( !stream.isOpen() ) |
| 68 | return false; |
| 69 | |
| 70 | Image img( stream ); |
| 71 | |
| 72 | if ( img.getPixelsPtr() == NULL ) |
| 73 | return false; |
| 74 | |
| 75 | /** Implementation specification taken from raylib ( LICENSE zlib/libpng ). Copyright (c) Ramon |
| 76 | * Santamaria (@raysan5) */ |
| 77 | int x = 0; |
| 78 | int y = 0; |
| 79 | int w = img.getWidth(); |
| 80 | int h = img.getHeight(); |
| 81 | |
| 82 | for ( y = 0; y < h; y++ ) { |
| 83 | for ( x = 0; x < w; x++ ) { |
| 84 | if ( img.getPixel( x, y ) != key ) |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | if ( img.getPixel( x, y ) != key ) |
| 89 | break; |
| 90 | } |
| 91 | |
| 92 | int charSpacing = x; |
| 93 | int lineSpacing = y; |
| 94 | int charRowHeight = 0; |
| 95 | |
| 96 | while ( img.getPixel( charSpacing, lineSpacing + charRowHeight ) != key ) |
| 97 | charRowHeight++; |
| 98 | |
| 99 | int charHeight = charRowHeight; |
| 100 | int index = 0; |
| 101 | |
| 102 | mFontSize = charHeight; |
| 103 | |
| 104 | int lineToRead = 0; |
| 105 | int xPosToRead = charSpacing; |
| 106 | |
| 107 | GlyphTable& glyphs = mPages[mFontSize].glyphs; |
| 108 | |
| 109 | while ( ( lineSpacing + lineToRead * ( charHeight + lineSpacing ) ) < h ) { |
| 110 | while ( xPosToRead < w && |
| 111 | img.getPixel( xPosToRead, |
| 112 | lineSpacing + lineToRead * ( charHeight + lineSpacing ) ) != key ) { |
| 113 | int charWidth = 0; |
| 114 | |
| 115 | while ( img.getPixel( xPosToRead + charWidth, |
| 116 | lineSpacing + lineToRead * ( charHeight + lineSpacing ) ) != key ) |
| 117 | charWidth++; |
| 118 | |
| 119 | Glyph& glyph = glyphs[firstChar + index]; |
| 120 | |
| 121 | glyph.textureRect = |
| 122 | Rect( xPosToRead, lineSpacing + lineToRead * ( charHeight + lineSpacing ), |
| 123 | charWidth, charHeight ); |
nothing calls this directly
no test coverage detected