From 3e0265e632a8428db6c8d48ae273b0ee5bee3f36 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 14 Sep 2023 17:26:17 +0100 Subject: works with unicode --- lasertext/src/ofApp.cpp | 27 ++++++++++++++++++- lasertext/src/vectortext.h | 66 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 82 insertions(+), 11 deletions(-) (limited to 'lasertext/src') diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp index b0442bb..050b913 100644 --- a/lasertext/src/ofApp.cpp +++ b/lasertext/src/ofApp.cpp @@ -26,7 +26,8 @@ void ofApp::setup(){ //banner.loadFont("fonts/EMSDecorousScript.svg"); //2022 banner.loadFont("fonts/EMSQwandry.svg"); //2023 //banner.init("Everything Is Going To Be Alright"); - banner.init("No Pleasure is Too Guilty"); + //banner.init("No Pleasure is Too Guilty"); + banner.init("Casaimid lenár gcroíthe anoi"); override_banner.loadFont("fonts/EMSQwandry.svg"); @@ -159,6 +160,29 @@ void ofApp::save_settings(){ cout << "settings.xml saved!" < +#include + class glyph{ public: glyph(char c,float w,vector lines){ glyph(c,w,lines,ofColor(0,0,0)); } + glyph(string s,float w,vector lines){ + glyph(s,w,lines,ofColor(0,0,0)); + } glyph(char c,float w,vector lines,ofColor col){ - code=c; + string str(1, c); + glyph(str,w,lines,col); + } + glyph(string str,float w,vector 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 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 w=words; clear(); createWords(w); - enspace=getGlyph(' ').width; + enspace=getGlyph(" ").width; ofLog()<<"loaded "< 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, "<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 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 "<