MCPcopy Create free account
hub / github.com/SpartanJ/eepp / loadFromStream

Method loadFromStream

src/eepp/graphics/fontsprite.cpp:66–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66bool 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 );

Callers

nothing calls this directly

Calls 10

getPixelMethod · 0.80
getChannelsMethod · 0.80
setCoordinateTypeMethod · 0.80
isOpenMethod · 0.45
getPixelsPtrMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
createMaskFromColorMethod · 0.45
loadFromPixelsMethod · 0.45
setFilterMethod · 0.45

Tested by

no test coverage detected