summaryrefslogtreecommitdiffstats
path: root/src/unicoderange.cpp
diff options
context:
space:
mode:
authorFelipe Corr??a da Silva Sanches <juca@members.fsf.org>2008-06-16 01:24:19 +0000
committerJucaBlues <JucaBlues@users.sourceforge.net>2008-06-16 01:24:19 +0000
commit14566438b94c5dfd3d97f72d1926dd9a259734b6 (patch)
tree62c995ca215f3234e2409667945fc989521b52c2 /src/unicoderange.cpp
parentnew command: relink clone to copied object (diff)
downloadinkscape-14566438b94c5dfd3d97f72d1926dd9a259734b6.tar.gz
inkscape-14566438b94c5dfd3d97f72d1926dd9a259734b6.zip
UnicodeRange class implementation.
This class represents a range of unicode codepoints as used in the u1 and u2 attributes of glyph kerning nodes. (bzr r5949)
Diffstat (limited to 'src/unicoderange.cpp')
-rw-r--r--src/unicoderange.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/unicoderange.cpp b/src/unicoderange.cpp
new file mode 100644
index 000000000..c40891009
--- /dev/null
+++ b/src/unicoderange.cpp
@@ -0,0 +1,96 @@
+#include<unicoderange.h>
+
+static unsigned int hex2int(char* s){
+ int res=0;
+ int i=0, mul=1;
+ while(s[i+1]!='\0') i++;
+
+ while(i>=0){
+ if (s[i] > '9') res += mul * (s[i]-'A'+10);
+ else res += mul * (s[i]-'0');
+ i--;
+ mul*=16;
+ }
+ return res;
+}
+
+UnicodeRange::UnicodeRange(const gchar* value){
+ gchar* val = (gchar*) value;
+ while(val[0] != '\0'){
+ if (val[0]=='U' && val[1]=='+'){
+ val += add_range(val);
+ } else {
+// g_warning("adding unichar. unichar=%c", g_utf8_get_char(&val[0]));
+ this->unichars.push_back(g_utf8_get_char(&val[0]));
+ val++;
+ }
+ //skip spaces or commas
+ while(val[0]==' ' || val[0]==',') val++;
+ }
+}
+
+int
+UnicodeRange::add_range(gchar* val){
+ Urange r;
+ //U+
+ val+=2;
+ int i=0, count=2;
+ while(val[i]!='\0' && val[i]!='-' && val[i]!=' ' && val[i]!=',') i++;
+ r.start = (gchar*) malloc((i+1)*sizeof(gchar*));
+ strncpy(r.start, val, i);
+ r.start[i] = '\0';
+ val+=i;
+ count+=i;
+ i=0;
+ if (val[0]=='-'){
+ val++;
+ while(val[i]!='\0' && val[i]!='-' && val[i]!=' ' && val[i]!=',') i++;
+ r.end = (gchar*) malloc((i+1)*sizeof(gchar*));
+ strncpy(r.end, val, i);
+ r.end[i] = '\0';
+ val+=i;
+ count+=i;
+ } else {
+ r.end=NULL;
+ }
+// g_warning("adding range. from %s to %s", r.start, r.end);
+ this->range.push_back(r);
+ return count+1;
+}
+
+bool UnicodeRange::contains(gchar unicode){
+ for(unsigned int i=0;i<this->unichars.size();i++){
+ if ((gunichar) unicode == this->unichars[i]) return true;
+ }
+
+ unsigned int unival;
+ unival = g_utf8_get_char (&unicode);
+ g_warning("unival=%d", unival);
+ char uni[9] = "00000000";
+ uni[8]= '\0';
+ unsigned char val;
+ for (unsigned int i=7; unival>0; i--){
+ val = unival & 0xf;
+ unival = unival >> 4;
+ if (val < 10) uni[i] = '0' + val;
+ else uni[i] = 'A'+ val - 10;
+ }
+// g_warning("uni=%s", uni);
+
+ bool found;
+ for(unsigned int i=0;i<this->range.size();i++){
+ Urange r = this->range[i];
+ if (r.end){
+// g_warning("hex2int: start=%d", hex2int(r.start));
+// g_warning("hex2int: end=%d", hex2int(r.end));
+ if (unival >= hex2int(r.start) && unival <= hex2int(r.end)) return true;
+ } else {
+ found = true;
+ for (int pos=0;pos<8;pos++){
+ if (uni[pos]!='?' && uni[pos]!=r.start[pos]) found = false;
+ }
+ if (found) return true;
+ }
+ }
+ return false;
+}