Created
January 21, 2024 14:48
-
-
Save hiroMTB/e5c746c6403da714f74cf4f37b711451 to your computer and use it in GitHub Desktop.
Test code for ofTrueTypeFont
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup(){ | |
ofBackground(54, 54, 54, 255); | |
//old OF default is 96 - but this results in fonts looking larger than in other programs. | |
ofTrueTypeFont::setGlobalDpi(72); | |
verdana14.load("verdana.ttf", 50, true, true); | |
//verdana14.setLineHeight(18.0f); | |
//verdana14.setLetterSpacing(1.037); | |
} | |
void ofApp::draw(){ | |
ofPushMatrix(); | |
ofTranslate(200, 50); | |
ofSetColor(0, 0, 255); | |
ofDrawCircle(0, 0, 2); | |
ofSetColor(255); | |
string s = "ABC\n123"; | |
verdana14.drawString(s, 0, 0); | |
// Red Rect | |
ofRectangle bb = verdana14.getStringBoundingBox(s, 0, 0); | |
ofNoFill(); | |
ofSetColor(255,0,0); | |
ofDrawRectangle(bb); | |
// Green Line | |
float w = verdana14.stringWidth(s); | |
w *= bRight2Left ? 1 : -1; | |
ofSetColor(0, 255, 0); | |
ofDrawLine(0,100, w, 100); | |
ofPopMatrix(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
bRight2Left = !bRight2Left; | |
if(bRight2Left){ | |
verdana14.setDirection(OF_TTF_LEFT_TO_RIGHT); | |
}else{ | |
verdana14.setDirection(OF_TTF_RIGHT_TO_LEFT); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment