Are you subscribed to the LyX-devel list, or should I continue to email you direct?
On Wednesday 22 January 2003 2:55 pm, [EMAIL PROTECTED] wrote: > On Wed, 22 Jan 2003, Angus Leeming wrote: > > Looking through it... > > I'm not sure that Lars will enjoy his change of name in so many places > > ;-) > > > > You have a lot of code like: > > +#ifdef I18N > > + wchar_t c = par.getUChar(params, i); > > +#else > > char c = par.getUChar(params, i); > > +#endif > > > > Would it not be simpler to define a lyx::char_type in support/types.h and > > use that? Then you restrict the changes you have to make in future to one > > line of code only. > > Sounds an excellent idea. But to help guys like me who are poorly equipped > for coding, you should be more specific in your advice------means that I > need more concrete example code in support/types.h. Ok, I've patched support/types.h and applied the idea to your code in text.C. That should get you started. Ask Lars if he has a better name than 'char_type'. I believe that he has converted the code to use a different size than char for testing purposes. Maybe he has a patch that you could 'just apply'. You should do the same sort of thing for wchar_type. Your current code seems designed simply to make your life hard ;-) In lyxstring.C you have this: +#ifdef I18N + typedef wchar_t wchar_type; +#endif typedef char value_type; Can you not change it to +#ifdef I18N + typedef wchar_t value_type; +#else typedef char value_type; +#endif This holds true also if you decide to create support/wstring.[Ch] files. I guess that you get the pucture ;-) That would remove the need for all those +#ifdef I18N + wchar_type const c = getChar(i); +#else value_type const c = getChar(i); +#endif It should also work automatically for std::string. > > xforms/forms/form_preferences.fd: > > +#ifdef I18N > > +=============== FORM =============== > > +Name: form_preferences_cjk_fonts > > [snip] > > +#endif > > > > I take it that fdesign is happy with these #ifdefs and that the resulting > > xforms/forms/form_preferences.[Ch] that you also include in your patch > > are auto-generated? > > They should be auto-generated, but they were not. Maybe "ifdef I18N" in > form_preferences.fd is the reason ? I'm pretty sure that fdesign does not support these preprocessor commands. I would suggest removing the #ifdef I18N from form_preferences.fd. We'll autogenerate and compile an extra form, but only CJKLyX users will actually have it connected to the tabfolder. To me, this is an acceptable compromise. I'd rather not have special casing in the autogeneration code. > > graphics/PreviewLoader.C and other places too: > > - PreviewLoader::Status status(string const & latex_snippet) const; > > + PreviewLoader::Statue status(string const & latex_snippet) const; > > > > WHY? > > I was about to ask you for this subtle problem: when I compile > PreviewLoader.C without Status->Statue change, I get tons of errors a few > of which are > **************** > PreviewLoader.C:129: parse error before `int' > PreviewLoader.C:202: parse error before `int' > PreviewLoader.C:208: syntax error before `::' token > PreviewLoader.C:214: syntax error before `::' token > PreviewLoader.C:220: syntax error before `::' token > PreviewLoader.C:226: syntax error before `::' token > PreviewLoader.C:232: syntax error before `::' token > PreviewLoader.C:238: syntax error before `::' token > PreviewLoader.C:362: parse error before `int' > PreviewLoader.C:369: `pending_' was not declared in this scope > > > *************** > > The fact of the matter is that I do not touch any files in src/graphics > directory, except Makefile contains additional "-DI18N" CXXFLAG, which is > auto-generated from configure. The errors are incomprehensible to me and I > have found two work-arounds. One is that removing "-DI18N" from the > CXXFLAGS solves the problem, and the other is the change "Status->Statue" > which was adopted in the patch. I am sure that there must be better or > right way of solving the problem. It's incomprehensible to me too. I'll apply you patch and try it out... I'm actually amazed at how little LyX really needs altering ;-) Angus
Index: src/text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.283 diff -u -p -r1.283 text.C --- src/text.C 27 Dec 2002 11:08:08 -0000 1.283 +++ src/text.C 22 Jan 2003 15:57:13 -0000 @@ -47,6 +47,13 @@ using std::min; using std::endl; using std::pair; using lyx::pos_type; +using lyx::char_type; +using lyx::unsigned_char_type; + +#ifdef I18N + #include "lyxcodeconv.h" + extern LyXCodeConv codeconverter; +#endif namespace { @@ -192,13 +199,12 @@ unsigned char LyXText::transformChar(uns int LyXText::singleWidth(BufferView * bview, Paragraph * par, pos_type pos) const { - char const c = par->getChar(pos); + char_type const c = par->getChar(pos); return singleWidth(bview, par, pos, c); } - int LyXText::singleWidth(BufferView * bview, Paragraph * par, - pos_type pos, char c) const + pos_type pos, char_type c) const { LyXFont const font = getFont(bview->buffer(), par, pos); @@ -613,7 +619,16 @@ void LyXText::drawChars(DrawRowParams & // first character string str; +#ifdef I18N + wchar_t wcs[2]; + char mbs[5]; + wcs[0] = p.row->par()->getChar(pos); + wcs[1] = 0; + wcstombs(mbs, wcs, 5); + str += mbs; +#else str += p.row->par()->getChar(pos); +#endif if (arabic) { unsigned char c = str[0]; str[0] = transformChar(c, p.row->par(), pos); @@ -622,7 +637,7 @@ void LyXText::drawChars(DrawRowParams & // collect as much similar chars as we can while (vpos <= last && (pos = vis2log(vpos)) >= 0) { - char c = p.row->par()->getChar(pos); + char_type c = p.row->par()->getChar(pos); if (!IsPrintableNonspace(c)) break; @@ -637,7 +652,14 @@ void LyXText::drawChars(DrawRowParams & if (arabic) c = transformChar(c, p.row->par(), pos); +#ifdef I18N + wcs[0] = c; + wcs[1] = 0; + wcstombs(mbs, wcs, 5); + str += mbs; +#else str += c; +#endif ++vpos; } @@ -655,8 +677,7 @@ bool LyXText::draw(DrawRowParams & p, po LyXFont const & orig_font = getFont(p.bv->buffer(), par, pos); float const orig_x = p.x; - - char const c = par->getChar(pos); + char_type const c = par->getChar(pos); if (IsNewlineChar(c)) { ++vpos; @@ -1000,7 +1021,7 @@ LyXText::nextBreakPoint(BufferView * bvi bool doitonetime = true; while (doitonetime || ((x < width) && (i < last))) { doitonetime = false; - char const c = par->getChar(i); + char_type const c = par->getChar(i); Inset * in = 0; if (c == Paragraph::META_INSET) in = par->getInset(i); @@ -1047,6 +1068,10 @@ LyXText::nextBreakPoint(BufferView * bvi } else { if (par->isLineSeparator(i)) last_separator = i; +#ifdef I18N + if (codeconverter.lyxIsLineSeparatorChar(c)) + last_separator = i-1; +#endif x += singleWidth(bview, par, i, c); } ++i; @@ -1830,7 +1855,7 @@ void LyXText::redoParagraph(BufferView * // insert a character, moves all the following breaks in the // same Paragraph one to the right and make a rebreak -void LyXText::insertChar(BufferView * bview, char c) +void LyXText::insertChar(BufferView * bview, char_type c) { setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next()); @@ -1863,7 +1888,7 @@ void LyXText::insertChar(BufferView * bv number(bview); // Set current_font.number to ON if (cursor.pos() > 0) { - char const c = cursor.par()->getChar(cursor.pos() - 1); + char_type const c = cursor.par()->getChar(cursor.pos() - 1); if (contains(number_unary_operators, c) && (cursor.pos() == 1 || cursor.par()->isSeparator(cursor.pos() - 2) || @@ -2609,7 +2634,7 @@ void LyXText::changeRegionCase(BufferVie pos = 0; continue; } - unsigned char c = par->getChar(pos); + unsigned_char_type c = par->getChar(pos); if (!IsInsetChar(c) && !IsHfillChar(c)) { switch (action) { case text_lowercase: @@ -2652,9 +2677,8 @@ void LyXText::transposeChars(BufferView // We are at the end of a paragraph. if (tmppos == tmppar->size() - 1) return; - - unsigned char c1 = tmppar->getChar(tmppos); - unsigned char c2 = tmppar->getChar(tmppos - 1); + unsigned_char_type c1 = tmppar->getChar(tmppos); + unsigned_char_type c2 = tmppar->getChar(tmppos - 1); if (c1 != Paragraph::META_INSET && c2 != Paragraph::META_INSET) { Index: src/support/types.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/types.h,v retrieving revision 1.7 diff -u -p -r1.7 types.h --- src/support/types.h 25 Sep 2002 10:03:41 -0000 1.7 +++ src/support/types.h 22 Jan 2003 15:57:17 -0000 @@ -20,6 +20,12 @@ namespace lyx { + /** The type LyX uses to hold characters. + * char_type == char except in CJK-LyX where char_type == wchar_t. + */ + typedef char char_type; + typedef unsigned char unsigned_char_type; + /// a type for positions used in paragraphs // needs to be signed for a while to hold the special value -1 that is // used there...