diff options
| -rw-r--r-- | lasertext/src/ofApp.cpp | 28 | ||||
| -rw-r--r-- | lasertext/src/vectortext.h | 66 |
2 files changed, 83 insertions, 11 deletions
diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp index 636aaa0..52f6d57 100644 --- a/lasertext/src/ofApp.cpp +++ b/lasertext/src/ofApp.cpp @@ -27,7 +27,9 @@ void ofApp::setup(){ banner.loadFont("fonts/EMSQwandry.svg"); //2023 //banner.init("Everything Is Going To Be Alright"); //banner.init("No Pleasure is Too Guilty"); - banner.init("Éalú Le Grá"); + //banner.init("Éalú Le Grá"); + + banner.init("Casaimid lenár gcroíthe anoi"); override_banner.loadFont("fonts/EMSQwandry.svg"); @@ -164,6 +166,29 @@ void ofApp::save_settings(){ cout << "settings.xml saved!" <<std::endl; } +string runUnixCommandAndCaptureOutput(string cmd) { + char buffer[128]; + string result = ""; + FILE* pipe = popen(cmd.c_str(), "r"); + if (!pipe) throw std::runtime_error("popen() failed!"); + try { + while (!feof(pipe)) { + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + } catch (...) { + pclose(pipe); + throw; + } + pclose(pipe); + return result; +} + +void runUnixCommand(string cmd) { + system(cmd.c_str()); + return; +} + //-------------------------------------------------------------- void ofApp::update(){ banner.update(text_speed,true); @@ -336,6 +361,7 @@ void ofApp::keyReleased(int key){ case '1':{ ofLog()<<"sending test phrase 1"; override_banner.init("The latin quarter"); + runUnixCommand("say 'The latin quarter'"); break; } case 's':{ diff --git a/lasertext/src/vectortext.h b/lasertext/src/vectortext.h index 6fa8acc..94104e9 100644 --- a/lasertext/src/vectortext.h +++ b/lasertext/src/vectortext.h @@ -5,13 +5,23 @@ #include "lineTransformer.h" #include "colourPolyline.h" +#include <unicode/utypes.h> +#include <unicode/uchar.h> + class glyph{ public: glyph(char c,float w,vector<ofPolyline> lines){ glyph(c,w,lines,ofColor(0,0,0)); } + glyph(string s,float w,vector<ofPolyline> lines){ + glyph(s,w,lines,ofColor(0,0,0)); + } glyph(char c,float w,vector<ofPolyline> lines,ofColor col){ - code=c; + string str(1, c); + glyph(str,w,lines,col); + } + glyph(string str,float w,vector<ofPolyline> lines,ofColor col){ + chr=str; width=w; outline=lines; colour=col; @@ -26,7 +36,7 @@ public: void randomiseColour(){ colour=ofColor::fromHsb(ofRandom(255.0),225,255); } - char code; + string chr; float width; vector<ofPolyline> outline; ofColor colour; @@ -121,7 +131,7 @@ public: string text(){ string s; for (auto& w:words) { - for (auto& g:w.glyphs) s+=ofToString(g.code); + for (auto& g:w.glyphs) s+=g.chr; } return s; } @@ -130,7 +140,7 @@ public: vector<glyphWord> w=words; clear(); createWords(w); - enspace=getGlyph(' ').width; + enspace=getGlyph(" ").width; ofLog()<<"loaded "<<path.stem().string(); }else{ ofLog()<<"unable to load "<<path<<" check data/ folder"; @@ -142,13 +152,20 @@ public: vector<string> m=split(message); for (auto& word: m){ glyphWord w; + int pos=0; for (auto& c: word){ - w.glyphs.push_back(getGlyph(c, + string uniglyph = ofUTF8Substring(word, pos, 1); + if (c<0){ + ofLog()<<"got unicode glyph, "<<uniglyph; + + } + w.glyphs.push_back(getGlyph(uniglyph, usePalette? palette[ofRandom(palette.size())]: //112->231 hue sat 0->255 brightness 255 ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255) )); + pos++; } words.push_back(w); } @@ -159,19 +176,48 @@ public: for (auto& _w:_words) { glyphWord w; for (auto& g: _w.glyphs){ - w.glyphs.push_back(getGlyph(g.code,g.colour)); + w.glyphs.push_back(getGlyph(g.chr,g.colour)); } words.push_back(w); } } - glyph getGlyph(char c,ofColor col=ofColor(255,255,255)){ + glyph getGlyph(string c,ofColor col=ofColor(255,255,255)){ vector<ofPolyline> shapes; ofPolyline shape; - string elementPath = "/svg/defs/font/glyph[@unicode='"+ofToString(c)+"']"; + string elementPath; +/* +[notice ] getGlyph placed ? for missing char -61 (?) +[notice ] getGlyph placed ? for missing char -119 (?) +[notice ] getGlyph placed ? for missing char -61 (?) +[notice ] getGlyph placed ? for missing char -70 (?) +[notice ] getGlyph placed ? for missing char -61 (?) +[notice ] getGlyph placed ? for missing char -95 (?) +hack to add unicode support for these chars + + if (c==-61){ + elementPath = '/svg/defs/font/glyph[@unicode="Ĕ"]'; //Ebreve + //this doesn't actually display the accent + ofLog()<<"getGlyph substituted 'Ĕ' for missing char -61"; + } + if (c==-119||c==-70||c==-95){ + elementPath = '/svg/defs/font/glyph[@unicode="È"]'; //Egrave + //this doesn't actually find anything + ofLog()<<"getGlyph substituted 'È' for missing char -119"; + } + + ofUTF8Substring(const std::string & utf8, size_t pos, size_t len); + else { + */ + elementPath = "/svg/defs/font/glyph[@unicode='"+ofToString(c)+"']"; + //} + + /* if(SVGFont.findFirst(elementPath) == 0 ){ elementPath = "/svg/defs/font/glyph[@unicode='?']"; + ofLog()<<"getGlyph placed ? for missing char "<<c; } + */ ofXml xmlElement = SVGFont.findFirst(elementPath); @@ -193,8 +239,8 @@ public: if (shape.size()) shapes.push_back(shape); return glyph(c,charWidth,shapes,col); } - void addGlyph(char g,bool usePalette=false){ - if (g==' ') words.push_back(glyphWord()); + void addGlyph(string g,bool usePalette=false){ + if (g==" ") words.push_back(glyphWord()); else { words[words.size()-1].glyphs.push_back(getGlyph(g, usePalette? |
