Browse Source

Adapted to "pointer chasing" Magnum changes.

pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
5b0d0fe943
  1. 14
      src/Plugins/MagnumFont/MagnumFont.cpp
  2. 2
      src/Plugins/MagnumFont/MagnumFont.h
  3. 2
      src/Plugins/MagnumFont/Test/MagnumFontTest.cpp
  4. 26
      src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp
  5. 2
      src/Plugins/MagnumFontConverter/MagnumFontConverter.h
  6. 2
      src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp

14
src/Plugins/MagnumFont/MagnumFont.cpp

@ -45,13 +45,13 @@ struct MagnumFont::Data {
namespace {
class MagnumFontLayouter: public AbstractLayouter {
public:
explicit MagnumFontLayouter(const std::unordered_map<char32_t, UnsignedInt>& glyphId, const std::vector<Vector2>& glyphAdvance, const GlyphCache* cache, Float fontSize, Float textSize, const std::string& text);
explicit MagnumFontLayouter(const std::unordered_map<char32_t, UnsignedInt>& glyphId, const std::vector<Vector2>& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, const std::string& text);
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(UnsignedInt i) override;
private:
const std::vector<Vector2>& glyphAdvance;
const GlyphCache* const cache;
const GlyphCache& cache;
const Float fontSize, textSize;
std::vector<UnsignedInt> glyphs;
};
@ -194,13 +194,13 @@ GlyphCache* MagnumFont::doCreateGlyphCache() {
return cache;
}
AbstractLayouter* MagnumFont::doLayout(const GlyphCache* cache, Float size, const std::string& text) {
AbstractLayouter* MagnumFont::doLayout(const GlyphCache& cache, Float size, const std::string& text) {
return new MagnumFontLayouter(_opened->glyphId, _opened->glyphAdvance, cache, this->size(), size, text);
}
namespace {
MagnumFontLayouter::MagnumFontLayouter(const std::unordered_map<char32_t, UnsignedInt>& glyphId, const std::vector<Vector2>& glyphAdvance, const GlyphCache* cache, Float fontSize, Float textSize, const std::string& text): glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize) {
MagnumFontLayouter::MagnumFontLayouter(const std::unordered_map<char32_t, UnsignedInt>& glyphId, const std::vector<Vector2>& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, const std::string& text): glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize) {
/* Get glyph codes from characters */
glyphs.reserve(text.size());
for(std::size_t i = 0; i != text.size(); ) {
@ -216,12 +216,12 @@ std::tuple<Rectangle, Rectangle, Vector2> MagnumFontLayouter::renderGlyph(Unsign
/* Position of the texture in the resulting glyph, texture coordinates */
Vector2i position;
Rectanglei rectangle;
std::tie(position, rectangle) = (*cache)[glyphs[i]];
std::tie(position, rectangle) = cache[glyphs[i]];
const Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize,
Vector2(rectangle.size())/fontSize);
const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache->textureSize(),
Vector2(rectangle.topRight())/cache->textureSize());
const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache.textureSize(),
Vector2(rectangle.topRight())/cache.textureSize());
/* Absolute quad position, composed from cursor position, glyph offset
and texture position, denormalized to requested text size */

2
src/Plugins/MagnumFont/MagnumFont.h

@ -120,7 +120,7 @@ class MagnumFont: public AbstractFont {
GlyphCache* doCreateGlyphCache() override;
AbstractLayouter* doLayout(const GlyphCache* cache, Float size, const std::string& text) override;
AbstractLayouter* doLayout(const GlyphCache& cache, Float size, const std::string& text) override;
Data* _opened;

2
src/Plugins/MagnumFont/Test/MagnumFontTest.cpp

@ -63,7 +63,7 @@ void MagnumFontTest::layout() {
cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}});
cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}});
AbstractLayouter* layouter = font.layout(&cache, 0.5f, "Wave");
AbstractLayouter* layouter = font.layout(cache, 0.5f, "Wave");
CORRADE_VERIFY(layouter);
CORRADE_COMPARE(layouter->glyphCount(), 4);

26
src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp

@ -43,21 +43,21 @@ auto MagnumFontConverter::doFeatures() const -> Features {
return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile;
}
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const {
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const {
Utility::Configuration configuration;
configuration.setValue("version", 1);
configuration.setValue("image", Utility::Directory::filename(filename) + ".tga");
configuration.setValue("originalImageSize", cache->textureSize());
configuration.setValue("padding", cache->padding());
configuration.setValue("fontSize", font->size());
configuration.setValue("originalImageSize", cache.textureSize());
configuration.setValue("padding", cache.padding());
configuration.setValue("fontSize", font.size());
/* Compress glyph IDs so the glyphs are in consecutive array, glyph 0
should stay at position 0 */
std::unordered_map<UnsignedInt, UnsignedInt> glyphIdMap;
glyphIdMap.reserve(cache->glyphCount());
glyphIdMap.reserve(cache.glyphCount());
glyphIdMap.emplace(0, 0);
for(const std::pair<UnsignedInt, std::pair<Vector2i, Rectanglei>>& glyph: *cache)
for(const std::pair<UnsignedInt, std::pair<Vector2i, Rectanglei>>& glyph: cache)
glyphIdMap.emplace(glyph.first, glyphIdMap.size());
/** @todo Save only glyphs contained in @p characters */
@ -70,7 +70,7 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFont
/* Character->glyph map, map glyph IDs to new ones */
for(const char32_t c: characters) {
Utility::ConfigurationGroup* group = configuration.addGroup("char");
const UnsignedInt glyphId = font->glyphId(c);
const UnsignedInt glyphId = font.glyphId(c);
group->setValue("unicode", c);
/* Map old glyph ID to new, if not found, map to glyph 0 */
@ -82,12 +82,12 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFont
from the values so they aren't added twice when using the font later */
/** @todo Some better way to handle this padding stuff */
for(UnsignedInt oldGlyphId: inverseGlyphIdMap) {
std::pair<Vector2i, Rectanglei> glyph = (*cache)[oldGlyphId];
std::pair<Vector2i, Rectanglei> glyph = cache[oldGlyphId];
Utility::ConfigurationGroup* group = configuration.addGroup("glyph");
group->setValue("advance", font->glyphAdvance(oldGlyphId));
group->setValue("position", glyph.first+cache->padding());
group->setValue("rectangle", Rectanglei(glyph.second.bottomLeft()+cache->padding(),
glyph.second.topRight()-cache->padding()));
group->setValue("advance", font.glyphAdvance(oldGlyphId));
group->setValue("position", glyph.first+cache.padding());
group->setValue("rectangle", Rectanglei(glyph.second.bottomLeft()+cache.padding(),
glyph.second.topRight()-cache.padding()));
}
std::ostringstream confOut;
@ -98,7 +98,7 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFont
/* Save cache image */
Image2D image(ImageFormat::Red, ImageType::UnsignedByte);
cache->texture()->image(0, image);
cache.texture().image(0, image);
auto tgaData = Trade::TgaImageConverter().exportToData(image);
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> out;

2
src/Plugins/MagnumFontConverter/MagnumFontConverter.h

@ -48,7 +48,7 @@ class MagnumFontConverter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override;
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const override;
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override;
};
}}

2
src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp

@ -77,7 +77,7 @@ void MagnumFontConverterTest::exportFont() {
/* Convert the file */
MagnumFontConverter converter;
converter.exportFontToFile(&font, &cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave");
converter.exportFontToFile(font, cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave");
/* Verify font parameters */
/** @todo This might behave differently elsewhere due to unspecified order of glyphs in cache */

Loading…
Cancel
Save