-
Notifications
You must be signed in to change notification settings - Fork 1
/
ofxArcText.cpp
executable file
·70 lines (58 loc) · 2.12 KB
/
ofxArcText.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "ofxArcText.h"
ofxArcText::ofxArcText() {
align = CENTER;
showDebug = false;
}
float ofxArcText::getCharacterWidth(char ch) {
if (ch==' ') ch='i';
return cps[ch-NUM_CHARACTER_TO_START].setWidth;
}
void ofxArcText::drawStringAsShapes(string text, float x, float y, float radius) {
drawString(text,x,y,radius,true);
}
void ofxArcText::drawString(string text, float x, float y, float radius, bool asShapes) {
ofPushMatrix();
ofTranslate(x,y);
float angles[text.length()];
float widths[text.length()];
float totalAngle = 0;
for (int i=0; i<text.length(); i++) {
widths[i] = getCharacterWidth(text.at(i)) * letterSpacing;
angles[i] = atan(widths[i]/radius);
totalAngle += angles[i];
}
switch (align) {
case LEFT: break;
case CENTER: ofRotateZ(ofRadToDeg(totalAngle/2)); break;
case RIGHT: ofRotateZ(ofRadToDeg(totalAngle)); break;
}
if (showDebug) {
ofNoFill();
ofCircle(0,0,radius);
ofLine(0,0,0,radius);
ofPushMatrix();
for (int i=0; i<text.length(); i++) {
ofRotateZ(-ofRadToDeg(angles[i]));
ofLine(0,0,0,radius);
}
ofPopMatrix();
}
for (int i=0; i<text.length(); i++) {
ofPushMatrix();
ofTranslate(0, radius);
ofRotateZ(-ofRadToDeg(angles[i])/2); //local rotation, use this or center letter before rotating
if (asShapes) ofTrueTypeFont::drawStringAsShapes(ofToString((char)text.at(i)),0,0);
else ofTrueTypeFont::drawString(ofToString((char)text.at(i)),0,0);
ofPopMatrix();
ofRotateZ(-ofRadToDeg(angles[i]));
}
ofPopMatrix();
//for (int i=0; i<text.length(); i++) {
// float opposite = getCharacterWidth(text.at(i)) * letterSpacing;
// float angle = atan(opposite/radius) / 2;
// ofRotateZ(-ofRadToDeg(angle));
// string s = ofToString((char)text.at(i));
// ofTrueTypeFont::drawString(s,-widths[i]/2,radius);
// ofRotateZ(-ofRadToDeg(angle));
//}
}