i can 1 character @ time using em_getcharformat, extremely slow.
one idea somehow use itextdocument/itextfont interfaces, other use em_streamout message , manually parse rtf. can't decide approach better , fuzzy on implementation details. appreciate help, thanks!
i've found solution satisfies me , think share you:
the itextrange interface contains useful method expand can used find continuous runs of constant character (tomcharformat) , paragraph (tomparaformat) formatting.
here sample code (warning: code proof-of-concept spaghetti without error handling, apply refactoring needed):
// necessary interfaces iricheditole* ole; sendmessage(hwndrichedit, em_getoleinterface, 0, (lparam)&ole); itextdocument* doc; ole->queryinterface(__uuidof(itextdocument), (void**)&doc); long start = 0; // total length: itextrange* range; doc->range(start, start, &range); range->expand(tomstory, null); long eof; range->getend(&eof); // extract formatting: struct textcharformat { long start, length; dword effects; } std::vector<textcharformat> fs; while(start < eof - 1) { doc->range(start, start, &range); long n; range->expand(tomcharformat, &n); // <-- magic happens here itextfont* font; range->getfont(&font); dword effects = 0; long flag; font->getbold(&flag); if (flag == tomtrue) effects |= cfe_bold; font->getitalic(&flag); if (flag == tomtrue) effects |= cfe_italic; font->getunderline(&flag); if (flag == tomsingle) effects |= cfe_underline; font->getstrikethrough(&flag); if (flag == tomtrue) effects |= cfe_strikeout; if (effects) { textcharformat f = { start, n, effects }; fs.push_back(f); } start += n; }
Comments
Post a Comment