foreach (const Symbol& c , symbols()) { QString charDef="{\"from\":"; charDef+=charCode(c.id); charDef+=QString(",\"to\":"); typedef QMap<ushort,int>::ConstIterator Kerning; for ( Kerning k = c.kerning.begin();k!=c.kerning.end();k++) { QString def = charDef; def+=charCode(k.key()); def+=QString(",\"offset\":")+QString().number(k.value())+QString("}"); kernings+=QString("\t\t")+def+QString(",\n"); } }
WString WKeyEvent::text() const { int c = charCode(); if (c != 0) { char buf[10]; // 4 is enough char *ptr = buf; try { rapidxml::xml_document<>::insert_coded_character<0>(ptr, charCode()); } catch (rapidxml::parse_error& e) { LOG_ERROR("charcode: " << e.what()); return WString(); } return WString::fromUTF8(std::string(buf, ptr)); } else return WString(); }
int KeyboardEvent::keyCode() const { // IE: virtual key code for keyup/keydown, character code for keypress // Firefox: virtual key code for keyup/keydown, zero for keypress // We match IE. if (!m_keyEvent) return 0; if (type() == eventNames().keydownEvent || type() == eventNames().keyupEvent) return m_keyEvent->windowsVirtualKeyCode(); return charCode(); }
int KeyboardEvent::keyCode() const { // IE: virtual key code for keyup/keydown, character code for keypress // Firefox: virtual key code for keyup/keydown, zero for keypress // We match IE. if (!m_keyEvent) return 0; if (type() == EventTypeNames::keydown || type() == EventTypeNames::keyup) return windowsVirtualKeyCodeWithoutLocation(m_keyEvent->windowsVirtualKeyCode()); return charCode(); }
int KeyboardEvent::keyCode() const { // IE: virtual key code for keyup/keydown, character code for keypress // Firefox: virtual key code for keyup/keydown, zero for keypress // We match IE. if (!m_keyEvent) return 0; #if OS(ANDROID) // FIXME: Check to see if this applies to other OS. // If the key event belongs to IME composition then propagate to JS. if (m_keyEvent->nativeKeyCode == 0xE5) // VKEY_PROCESSKEY return m_keyEvent->nativeKeyCode; #endif if (type() == EventTypeNames::keydown || type() == EventTypeNames::keyup) return m_keyEvent->windowsKeyCode; return charCode(); }
bool LuaExporter::Export(QByteArray& out) { QString res; if (m_write_function) res+="return {\n"; const QString p(m_write_function ? "\t":""); res+=p+QString("file=\"")+texFilename()+QString(m_write_function ? "\",\n" : "\"\n"); res+=p+QString("height=")+QString().number(metrics().height)+QString(m_write_function?",\n":"\n"); res+=p+QString("description={\n"); res+=p+QString("\tfamily=\"")+fontConfig()->family()+QString("\",\n"); res+=p+QString("\tstyle=\"")+fontConfig()->style()+QString("\",\n"); res+=p+QString("\tsize=")+QString().number(fontConfig()->size())+QString("\n"); res+=p+QString(m_write_function?"},\n":"}\n"); res+=p+QString("metrics={\n"); res+=p+QString("\tascender=")+QString().number(metrics().ascender)+QString(",\n"); res+=p+QString("\tdescender=")+QString().number(metrics().descender)+QString(",\n"); res+=p+QString("\theight=")+QString().number(metrics().height)+QString("\n"); res+=p+QString(m_write_function?"},\n":"}\n"); res+=p+QString("texture={\n"); res+=p+QString("\tfile=\"")+texFilename()+QString("\",\n"); res+=p+QString("\twidth=")+QString().number(texWidth())+QString(",\n"); res+=p+QString("\theight=")+QString().number(texHeight())+QString("\n"); res+=p+QString(m_write_function?"},\n":"}\n"); res+=p+QString("chars={\n"); foreach (const Symbol& c , symbols()) { QString charDef="{char="; charDef+=charCode(c.id); charDef+=QString(","); charDef+=QString("width=")+QString().number(c.advance)+QString(","); charDef+=QString("x=")+QString().number(c.placeX)+QString(","); charDef+=QString("y=")+QString().number(c.placeY)+QString(","); charDef+=QString("w=")+QString().number(c.placeW)+QString(","); charDef+=QString("h=")+QString().number(c.placeH)+QString(","); charDef+=QString("ox=")+QString().number(c.offsetX)+QString(","); charDef+=QString("oy=")+QString().number(c.offsetY)+QString("}"); res+=p+QString("\t")+charDef+QString(",\n"); }
bool JsExporter::Export(QByteArray& out) { QString res = "var font = {\n"; res+=QString("\t\"file\":\"")+texFilename()+QString("\",\n"); res+=QString("\t\"height\":")+QString().number(metrics().height)+QString(",\n"); res+=QString("\t\"description\":{\n"); res+=QString("\t\t\"family\":\"")+fontConfig()->family()+QString("\",\n"); res+=QString("\t\t\"style\":\"")+fontConfig()->style()+QString("\",\n"); res+=QString("\t\t\"size\":")+QString().number(fontConfig()->size())+QString("\n"); res+=QString("\t},\n"); res+=QString("\t\"metrics\":{\n"); res+=QString("\t\t\"ascender\":")+QString().number(metrics().ascender)+QString(",\n"); res+=QString("\t\t\"descender\":")+QString().number(metrics().descender)+QString(",\n"); res+=QString("\t\t\"height\":")+QString().number(metrics().height)+QString("\n"); res+=QString("\t},\n"); res+=QString("\t\"texture\":{\n"); res+=QString("\t\t\"file\":\"")+texFilename()+QString("\",\n"); res+=QString("\t\t\"width\":")+QString().number(texWidth())+QString(",\n"); res+=QString("\t\t\"height\":")+QString().number(texHeight())+QString("\n"); res+=QString("\t},\n"); res+=QString("\t\"chars\":{\n"); foreach (const Symbol& c , symbols()) { QString charDef=charCode(c.id); charDef+=QString(":{"); charDef+=QString("\"width\":")+QString().number(c.advance)+QString(","); charDef+=QString("\"x\":")+QString().number(c.placeX)+QString(","); charDef+=QString("\"y\":")+QString().number(c.placeY)+QString(","); charDef+=QString("\"w\":")+QString().number(c.placeW)+QString(","); charDef+=QString("\"h\":")+QString().number(c.placeH)+QString(","); charDef+=QString("\"ox\":")+QString().number(c.offsetX)+QString(","); charDef+=QString("\"oy\":")+QString().number(c.offsetY)+QString("}"); res+=QString("\t\t")+charDef+QString(",\n"); }
std::string WKeyEvent::text() const { return std::string() + (char)charCode(); }
void UT_UTF8Stringbuf::decodeURL() { if(!m_psz || !*m_psz) return; char * buff = (char*)g_try_malloc(byteLength() + 1); UT_return_if_fail( buff ); buff[0] = 0; UTF8Iterator J(this); const char * ptr = J.current(); UT_UCS4Char c = charCode(J.current()); char utf8cache[7]; utf8cache[6] = 0; UT_uint32 iCachePos = 0; UT_uint32 iCacheNeeded = 0; while (c != 0) { if(c == '%') { J.advance(); UT_UCS4Char b1 = charCode(J.current()); J.advance(); UT_UCS4Char b2 = charCode(J.current()); J.advance(); if(isalnum(b1) && isalnum(b2)) { b1 = s_charCode_to_hexval(b1); b2 = s_charCode_to_hexval(b2); UT_UCS4Char code = ((b1 << 4)& 0xf0) | (b2 & 0x0f); if(iCacheNeeded == 0) { // we start new utf8 sequence in the cache if ((code & 0x80) == 0) iCacheNeeded = 1; else if ((code & 0xe0) == 0xc0) iCacheNeeded = 2; else if ((code & 0xf0) == 0xe0) iCacheNeeded = 3; else if ((code & 0xf8) == 0xf0) iCacheNeeded = 4; else if ((code & 0xfc) == 0xf8) iCacheNeeded = 5; else if ((code & 0xfe) == 0xfc) iCacheNeeded = 6; utf8cache[0] = (char) code; utf8cache[iCacheNeeded] = 0; // make sure the sequence will be terminated iCachePos++; } else { // append to our cache utf8cache[iCachePos++] = (char) code; } if(iCacheNeeded == 0 && (code >= 0x7f && code <= 0xff)) { // the present character is not a valid start of utf8 sequence -- // this is almost certainly a character from the extended ASCII set // which was encoded directly according to the RFC 1738 scheme, we // just append it size_t iLenBuff = strlen(buff); size_t iLenLeft = byteLength() - iLenBuff; char * p = buff + iLenBuff; UT_Unicode::UCS4_to_UTF8(p, iLenLeft, code); // we need to null-terminate *p = 0; } if(iCacheNeeded && iCacheNeeded <= iCachePos) { UT_ASSERT_HARMLESS( iCacheNeeded == iCachePos ); // append the cache to our buffer UT_uint32 iLenBuff = strlen(buff); char * p = buff + iLenBuff; strcat(p, utf8cache); iCacheNeeded = iCachePos = 0; } } else { // this should not happen in encoded url and so we will ignore this token; // if we are in the middle of utf8 sequence; we will reset it iCacheNeeded = iCachePos = 0; } } else { J.advance(); // advance here, for the sake of the else clause below if(iCacheNeeded > iCachePos) { // we are processing a utf sequence, so just append this byte to our cache utf8cache[iCachePos++] = (char) c; } else { const char * p = J.current(); UT_uint32 iLen = p ? p - ptr : strlen(ptr); strncat(buff, ptr, iLen); } } ptr = J.current(); c = charCode(J.current()); } assign(buff); g_free(buff); }
/* this function escapes the string to provide for conformity with http://www.w3.org/TR/xlink/#link-locators, section 5.4 */ void UT_UTF8Stringbuf::escapeURL () { if(!m_psz || !*m_psz) return; // now work out how many exra characters we will need // need to do this first of all, since growing the string will invalidate all pointers UTF8Iterator I(this); UT_UCS4Char c; UT_uint32 iIncrease = 0; for(c = charCode(I.current()); c != 0; c = charCode(I.advance())) { UT_sint32 iByteLen = UT_Unicode::UTF8_ByteLength(c); if(iByteLen > 1) iIncrease += iByteLen; else if(c <= 0x20 || c > 0x7e || (!isalnum(c) && !strchr("$-_.+!*'(),", c))) iIncrease += 2; } grow(iIncrease); UT_uint32 iScheme = 0; if(!g_ascii_strncasecmp(m_psz, "ftp://", 6)) iScheme = 1; else if(!g_ascii_strncasecmp(m_psz, "http://", 7)) iScheme = 2; else if(!g_ascii_strncasecmp(m_psz, "gopher://", 9)) iScheme = 3; else if(!g_ascii_strncasecmp(m_psz, "mailto:", 7)) iScheme = 4; else if(!g_ascii_strncasecmp(m_psz, "news:", 5)) iScheme = 5; else if(!g_ascii_strncasecmp(m_psz, "nntp://", 7)) iScheme = 6; else if(!g_ascii_strncasecmp(m_psz, "telnet://", 9)) iScheme = 7; else if(!g_ascii_strncasecmp(m_psz, "wais://", 7)) iScheme = 8; else if(!g_ascii_strncasecmp(m_psz, "file://", 7)) iScheme = 9; else if(!g_ascii_strncasecmp(m_psz, "prospero://", 11)) iScheme = 10; // now we parse the string into its constituent parts char * p = strstr(m_psz, "://"); char * schm = NULL; char * user = NULL; char * pswd = NULL; char * host = NULL; char * port = NULL; char * last_quest = NULL; char * last_hash = NULL; char * last_slash = NULL; if(p) { user = p + 3; schm = user; p = strchr(p+3, '/'); } else if(iScheme == 4) { p = m_psz + 7; } else if(iScheme == 5) { p = m_psz + 5; } char * urlpath = p ? p : m_psz; if(urlpath != m_psz && iScheme != 4 && iScheme != 5) { *urlpath = 0; char * at = strrchr(user, '@'); if(!at) { user = NULL; } else { host = at + 1; port = strchr(host, ':'); if(port) port++; *at = 0; pswd = strchr(user, ':'); if(pswd) pswd++; *at = '@'; } *urlpath = '/'; } // find out the last /, ? and # -- we need these to work out if ?#& should be escaped // in http or not last_slash = strrchr(urlpath, '/'); last_quest = strrchr(urlpath, '?'); last_hash = strrchr(urlpath, '#'); if(last_quest < last_slash) last_quest = NULL; // this is not a query questionmark if(last_hash < last_slash) last_hash = NULL; char buff[30]; UTF8Iterator J(this); for(c = charCode(J.current()); c != 0; c = charCode(J.advance())) { p = (char*) J.current(); UT_sint32 iByteLen = UT_Unicode::UTF8_ByteLength(c); if (iByteLen > 1) // mutlibyte in utf-8; each byte is to be encoded { char bytes[20]; bytes[0] = 0; UT_sint32 j; for(j = 0; j < iByteLen; ++j) { UT_uint32 v = (unsigned char)p[j]; snprintf(buff, 30, "%%%02x", v); strcat(bytes,buff); } char * b = bytes; for(j = 0; j < iByteLen; ++j) { *p++ = *b++; } insert(p, b, strlen(b)); for(j = 0; j < iByteLen; ++j) { J.advance(); J.advance(); J.advance(); } J.retreat(); } else if(// all single byte chars that always have to be encoded (c <= 0x20 || c > 0x7e || (!isalnum(c) && !strchr("$-_.+!*'(),;/?:@=&#", c))) // between the path element and the scheme marker all reserved chars other than @ and : also need to // be encode || (p < urlpath && p >= schm && strchr(";/?=&#",c)) // in user name and pswd, colons and @ have to be encoded || ((user && host && p >= user && p < host - 1) && ((c == ':' && (!pswd || p != pswd - 1)) || c == '@')) // in the host part we also encode @ || (c == '@' && p >= host && p < urlpath) // in url paths, the requirements are scheme-specific // http scheme: "/?;" are reserved; encode all # other than the fragment marker, // all = before the parameter ? as well as all :, @, & || (p > urlpath && ((iScheme == 0 || iScheme == 2) && ((c=='?' && p!=last_quest) || (c=='#' && p!=last_hash) || (c=='=' && p<last_quest) || strchr(":@&", c)))) // in mailto are no reserved characters || (p > urlpath && (iScheme == 4 && strchr(";?:@=&#/",c))) // news, only @ is reserved || (p > urlpath && (iScheme == 5 && strchr(";?:=&#/",c))) // in all other schemes we escape the reserved characters except / || (p > urlpath && (iScheme != 0 && iScheme != 2 && iScheme != 4 && iScheme != 5) && strchr(";?:@=&#", c))) { UT_return_if_fail( p ); // we have to adjust any pointers we keep in line with the insertion if(last_quest >= p) last_quest += 2; if(last_hash >= p) last_hash += 2; if(last_slash >= p) last_slash += 2; if(host >= p) host += 2; if(pswd >= p) pswd += 2; if(user >= p) user += 2; if(port >= p) port += 2; UT_uint32 v = *p; snprintf(buff, 30, "%02x", v); *p++ = '%'; insert(p, buff, strlen(buff)); // move past the two new chars J.advance(); J.advance(); } } }