ofxMixedFont is an openFrameworks addon to handle multiple fonts. It can render UNICODE characters including color emoji. Tested on macOS.
- ofxMixedFont enables the user to handle multiple fonts as if they were single font
- ofxMixedFont can render UNICODE characters including color emoji (Google's CBLC+CBDT and Apple's SBIX)
- The user may overwrite typesetting function of ofxMixedFont by the use of std::function
- The user may create own font class that derived from ofxBaseFont class, and ofxMixedFont can be used with it
- Download it ( https://github.com/hironishihara/ofxMixedFont/archive/master.zip )
- Extract the zip file, then rename the extracted folder to
ofxMixedFont
- Put the
ofxMixedFont
folder inOF_ROOT/addons
-
Launch
projectGenerator
, then create new sketch with ofxMixedFont addon -
Close
projectGenerator
, then open the new sketch project -
Copy
libfreetype.a
inofxMixedFont/libs/freetype2/lib
and rename it tofreetype.a
, then substitutefreetype.a
inOF_ROOT/libs/freetype/lib/freetype.a
with it -
Put font files (ex.
yourFont.ttf
andemojiFont.ttf
) inYOUR_PROJECT/bin/data
-
Include
ofxMixedFont.hpp
andofxFT2Font.hpp
// ofApp.h #include "ofxMixedFont.hpp" #include "ofxFT2Font.hpp"
-
Declare an instance of
std::shared_ptr<ofxMixedFont>
andstd::shared_ptr<ofxFT2Font>
// ofApp.h class ofApp : public ofBaseApp{ ... std::shared_ptr<ofxMixedFont> mixedFont; std::shared_ptr<ofxFT2Font> yourFont, emojiFont; };
-
Load fonts
// ofApp.cpp void ofApp::setup(){ ... mixedFont = std::make_shared<ofxMixedFont>(); yourFont = std::make_shared<ofxFT2Font>("your_font.ttf", 64); emojiFont = std::make_shared<ofxFT2Font>("emoji_font.otf", 64); mixedFont->add(yourFont); mixedFont->add(emojiFont); mixedFont->add(std::make_shared<ofxFT2Font>("barfoo_font.otf", 64)); }
-
Draw string
// ofApp.cpp void ofApp::draw(){ ... mixedFont->drawString("こんにちは🙂", ofPoint(100, 100)); }
-
Overwrite typesetting function
// ofApp.cpp
void ofApp::draw(){
...
auto func = [&](const ofxBaseFontPtr &font, const ofPoint &point, ofxGlyphDataList &glyph_list) {
ofPoint pos = point;
for (auto &glyph : glyph_list) {
glyph.coord = pos;
if (glyph.props.code_point == U"\n") {
pos.x = point.x;
pos.y += font->getFontProps().line_height;
}
else if (glyph.props.code_point == U" ") {
pos.x += font->getFontProps().x_ppem / 2.f;
}
else if (glyph.props.code_point == U" ") {
pos.x += font->getFontProps().x_ppem;
}
else {
pos.x += glyph.props.advance;
}
}
};
mixedFont->drawString("こんにちは🙂", ofPoint(100, 100), func);
}
Refer ofxMixedFont.hpp
and ofxMixedFontUtil.hpp
with regard to other functions.
- Fork it ( http://github.com/hironishihara/ofxMixedFont/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Rebase your local changes against the master branch
- Make sure that your feature performs as expected
- Make sure that your feature properly works together with functions of ofxMixedFont
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
- macOS (10.12) + Xcode (8.1) + openFrameworks 0.9.4 (osx)
- kerning function
- ligature function
- range of unicode characters
- other directions (Right to Left, Top to Bottom, etc.)
ofxMixedFont is distributed under the MIT License. This gives everyone the freedoms to use ofxMixedFont in any context: commercial or non-commercial, public or private, open or closed source. Please see License for details.
ofxMixedFont includes the following:
Copyright (c) 2004 - openFrameworks Community
Licensed under the MIT license.
Copyright (c) 1996-2002, 2006 - David Turner, Robert Wilhelm, and Werner Lemberg
Licensed under the FreeType project license.
Copyright (c) 2000-2002, 2004, 2006-2016 - Guy Eric Schalnat, Andreas Dilger, John Bowler, Glenn Randers-Pehrson, and others
Licensed under the libpng license.
Copyright (c) 2010,2011,2012 Google, Inc.
Copyright (c) 2012 Mozilla Foundation
Copyright (c) 2011 Codethink Limited
Copyright (c) 2008,2010 Nokia Corporation and/or its subsidiary(-ies)
Copyright (c) 2009 Keith Stribley
Copyright (c) 2009 Martin Hosken and SIL International
Copyright (c) 2007 Chris Wilson
Copyright (c) 2006 Behdad Esfahbod
Copyright (c) 2005 David Turner
Copyright (c) 2004,2007,2008,2009,2010 Red Hat, Inc.
Copyright (c) 1998-2004 David Turner and Werner Lemberg
Licensed under the so-called "Old MIT" license.
Copyright (c) 1996-2010 Julian R Seward
Licensed under the BSD-style license.