@ -67,11 +67,11 @@ auto MagnumFont::doFeatures() const -> Features { return Feature::OpenData|Featu
bool MagnumFont : : doIsOpened ( ) const { return _opened ; }
bool MagnumFont : : doIsOpened ( ) const { return _opened ; }
void MagnumFont : : doOpenData ( const std : : vector < std : : pair < std : : string , Containers : : ArrayReference < const unsigned char > > > & data , const Float ) {
std : : pair < Float , Float > MagnumFont : : doOpenData ( const std : : vector < std : : pair < std : : string , Containers : : ArrayReference < const unsigned char > > > & data , const Float ) {
/* We need just the configuration file and image file */
/* We need just the configuration file and image file */
if ( data . size ( ) ! = 2 ) {
if ( data . size ( ) ! = 2 ) {
Error ( ) < < " Text::MagnumFont::openData(): wanted two files, got " < < data . size ( ) ;
Error ( ) < < " Text::MagnumFont::openData(): wanted two files, got " < < data . size ( ) ;
return ;
return { } ;
}
}
/* Open the configuration file */
/* Open the configuration file */
@ -79,51 +79,51 @@ void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers:
Utility : : Configuration conf ( in , Utility : : Configuration : : Flag : : SkipComments ) ;
Utility : : Configuration conf ( in , Utility : : Configuration : : Flag : : SkipComments ) ;
if ( ! conf . isValid ( ) | | conf . isEmpty ( ) ) {
if ( ! conf . isValid ( ) | | conf . isEmpty ( ) ) {
Error ( ) < < " Text::MagnumFont::openData(): cannot open file " < < data [ 0 ] . first ;
Error ( ) < < " Text::MagnumFont::openData(): cannot open file " < < data [ 0 ] . first ;
return ;
return { } ;
}
}
/* Check version */
/* Check version */
if ( conf . value < UnsignedInt > ( " version " ) ! = 1 ) {
if ( conf . value < UnsignedInt > ( " version " ) ! = 1 ) {
Error ( ) < < " Text::MagnumFont::openData(): unsupported file version, expected 1 but got "
Error ( ) < < " Text::MagnumFont::openData(): unsupported file version, expected 1 but got "
< < conf . value < UnsignedInt > ( " version " ) ;
< < conf . value < UnsignedInt > ( " version " ) ;
return ;
return { } ;
}
}
/* Check that we have also the image file */
/* Check that we have also the image file */
if ( conf . value ( " image " ) ! = data [ 1 ] . first ) {
if ( conf . value ( " image " ) ! = data [ 1 ] . first ) {
Error ( ) < < " Text::MagnumFont::openData(): expected file "
Error ( ) < < " Text::MagnumFont::openData(): expected file "
< < conf . value ( " image " ) < < " but got " < < data [ 1 ] . first ;
< < conf . value ( " image " ) < < " but got " < < data [ 1 ] . first ;
return ;
return { } ;
}
}
/* Open and load image file */
/* Open and load image file */
Trade : : TgaImporter importer ;
Trade : : TgaImporter importer ;
if ( ! importer . openData ( data [ 1 ] . second ) ) {
if ( ! importer . openData ( data [ 1 ] . second ) ) {
Error ( ) < < " Text::MagnumFont::openData(): cannot open image file " ;
Error ( ) < < " Text::MagnumFont::openData(): cannot open image file " ;
return ;
return { } ;
}
}
std : : optional < Trade : : ImageData2D > image = importer . image2D ( 0 ) ;
std : : optional < Trade : : ImageData2D > image = importer . image2D ( 0 ) ;
if ( ! image ) {
if ( ! image ) {
Error ( ) < < " Text::MagnumFont::openData(): cannot load image file " ;
Error ( ) < < " Text::MagnumFont::openData(): cannot load image file " ;
return ;
return { } ;
}
}
openInternal ( std : : move ( conf ) , std : : move ( * image ) ) ;
return openInternal ( std : : move ( conf ) , std : : move ( * image ) ) ;
}
}
void MagnumFont : : doOpenFile ( const std : : string & filename , Float ) {
std : : pair < Float , Float > MagnumFont : : doOpenFile ( const std : : string & filename , Float ) {
/* Open the configuration file */
/* Open the configuration file */
Utility : : Configuration conf ( filename , Utility : : Configuration : : Flag : : ReadOnly | Utility : : Configuration : : Flag : : SkipComments ) ;
Utility : : Configuration conf ( filename , Utility : : Configuration : : Flag : : ReadOnly | Utility : : Configuration : : Flag : : SkipComments ) ;
if ( ! conf . isValid ( ) | | conf . isEmpty ( ) ) {
if ( ! conf . isValid ( ) | | conf . isEmpty ( ) ) {
Error ( ) < < " Text::MagnumFont::openFile(): cannot open file " < < filename < < conf . isValid ( ) ;
Error ( ) < < " Text::MagnumFont::openFile(): cannot open file " < < filename < < conf . isValid ( ) ;
return ;
return { } ;
}
}
/* Check version */
/* Check version */
if ( conf . value < UnsignedInt > ( " version " ) ! = 1 ) {
if ( conf . value < UnsignedInt > ( " version " ) ! = 1 ) {
Error ( ) < < " Text::MagnumFont::openFile(): unsupported file version, expected 1 but got "
Error ( ) < < " Text::MagnumFont::openFile(): unsupported file version, expected 1 but got "
< < conf . value < UnsignedInt > ( " version " ) ;
< < conf . value < UnsignedInt > ( " version " ) ;
return ;
return { } ;
}
}
/* Open and load image file */
/* Open and load image file */
@ -131,21 +131,20 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) {
Trade : : TgaImporter importer ;
Trade : : TgaImporter importer ;
if ( ! importer . openFile ( imageFilename ) ) {
if ( ! importer . openFile ( imageFilename ) ) {
Error ( ) < < " Text::MagnumFont::openFile(): cannot open image file " < < imageFilename ;
Error ( ) < < " Text::MagnumFont::openFile(): cannot open image file " < < imageFilename ;
return ;
return { } ;
}
}
std : : optional < Trade : : ImageData2D > image = importer . image2D ( 0 ) ;
std : : optional < Trade : : ImageData2D > image = importer . image2D ( 0 ) ;
if ( ! image ) {
if ( ! image ) {
Error ( ) < < " Text::MagnumFont::openFile(): cannot load image file " ;
Error ( ) < < " Text::MagnumFont::openFile(): cannot load image file " ;
return ;
return { } ;
}
}
openInternal ( std : : move ( conf ) , std : : move ( * image ) ) ;
return openInternal ( std : : move ( conf ) , std : : move ( * image ) ) ;
}
}
void MagnumFont : : openInternal ( Utility : : Configuration & & conf , Trade : : ImageData2D & & image ) {
std : : pair < Float , Float > MagnumFont : : openInternal ( Utility : : Configuration & & conf , Trade : : ImageData2D & & image ) {
/* Everything okay, save the data internally */
/* Everything okay, save the data internally */
_opened = new Data { std : : move ( conf ) , std : : move ( image ) , { } , { } } ;
_opened = new Data { std : : move ( conf ) , std : : move ( image ) , { } , { } } ;
_size = _opened - > conf . value < Float > ( " fontSize " ) ;
/* Glyph advances */
/* Glyph advances */
const std : : vector < Utility : : ConfigurationGroup * > glyphs = _opened - > conf . groups ( " glyph " ) ;
const std : : vector < Utility : : ConfigurationGroup * > glyphs = _opened - > conf . groups ( " glyph " ) ;
@ -160,6 +159,8 @@ void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D&
CORRADE_INTERNAL_ASSERT ( glyphId < _opened - > glyphAdvance . size ( ) ) ;
CORRADE_INTERNAL_ASSERT ( glyphId < _opened - > glyphAdvance . size ( ) ) ;
_opened - > glyphId . emplace ( c - > value < char32_t > ( " unicode " ) , glyphId ) ;
_opened - > glyphId . emplace ( c - > value < char32_t > ( " unicode " ) , glyphId ) ;
}
}
return { _opened - > conf . value < Float > ( " fontSize " ) , 0 } ;
}
}
void MagnumFont : : doClose ( ) {
void MagnumFont : : doClose ( ) {