From 618ca28af6c651d992c6d1d64e07e07cd4458010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 9 Apr 2006 02:30:40 +0000 Subject: [PATCH] * support/types.h: introduce the char_type type * paragraph.h: make value_type point at char_type * other files: change some bald 'char' to 'char_type' git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13609 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/cursor.C | 7 ++++--- src/cursor.h | 2 +- src/frontends/Painter.h | 4 +++- src/frontends/font_metrics.h | 16 +++++++++------- src/frontends/qt2/QLPainter.C | 2 +- src/frontends/qt2/qfont_metrics.C | 9 +++++---- src/lyxtext.h | 2 +- src/paragraph.C | 6 +++--- src/paragraph.h | 3 ++- src/rowpainter.C | 9 +++++---- src/support/types.h | 6 ++++++ src/text.C | 13 +++++++------ src/text3.C | 2 +- 13 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/cursor.C b/src/cursor.C index 6556fa25d4..0ca25c2d20 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -52,6 +52,7 @@ #include #include +using lyx::char_type; using lyx::pit_type; using std::string; @@ -637,7 +638,7 @@ void LCursor::plainErase() void LCursor::markInsert() { - insert(char(0)); + insert(char_type(0)); } @@ -657,12 +658,12 @@ void LCursor::plainInsert(MathAtom const & t) void LCursor::insert(string const & str) { for_each(str.begin(), str.end(), - boost::bind(static_cast + boost::bind(static_cast (&LCursor::insert), this, _1)); } -void LCursor::insert(char c) +void LCursor::insert(char_type c) { //lyxerr << "LCursor::insert char '" << c << "'" << endl; BOOST_ASSERT(!empty()); diff --git a/src/cursor.h b/src/cursor.h index d02952f0af..ae0dcf900b 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -112,7 +112,7 @@ public: /// insert an inset void insert(InsetBase *); /// insert a single char - void insert(char c); + void insert(lyx::char_type c); /// insert a string void insert(std::string const & str); diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h index c5eaa2d958..668ec4b9b8 100644 --- a/src/frontends/Painter.h +++ b/src/frontends/Painter.h @@ -15,6 +15,8 @@ #include "LColor.h" +#include "support/types.h" + #include @@ -152,7 +154,7 @@ public: /// draw a char at position x, y (y is the baseline) virtual void text(int x, int y, - char c, LyXFont const & f) = 0; + lyx::char_type c, LyXFont const & f) = 0; /** * Draw a string and enclose it inside a rectangle. If diff --git a/src/frontends/font_metrics.h b/src/frontends/font_metrics.h index 6a83b25d03..4d4a79b83a 100644 --- a/src/frontends/font_metrics.h +++ b/src/frontends/font_metrics.h @@ -13,6 +13,8 @@ #ifndef FONT_METRICS_H #define FONT_METRICS_H +#include "support/types.h" + #include @@ -51,25 +53,25 @@ namespace font_metrics { return maxAscent(f) + maxDescent(f); } /// return the ascent of the char in the font - int ascent(char c, LyXFont const & f); + int ascent(lyx::char_type c, LyXFont const & f); /// return the descent of the char in the font - int descent(char c, LyXFont const & f); + int descent(lyx::char_type c, LyXFont const & f); /// return the descent of the char in the font - inline int height(char c, LyXFont const & f) { + inline int height(lyx::char_type c, LyXFont const & f) { return ascent(c, f) + descent(c, f); } /// return the left bearing of the char in the font - int lbearing(char c, LyXFont const & f); + int lbearing(lyx::char_type c, LyXFont const & f); /// return the right bearing of the char in the font - int rbearing(char c, LyXFont const & f); + int rbearing(lyx::char_type c, LyXFont const & f); /// return the inner width of the char in the font - inline int center(char c, LyXFont const & f) { + inline int center(lyx::char_type c, LyXFont const & f) { return (rbearing(c, f) - lbearing(c, f)) / 2; } /// return the width of the string in the font int width(char const * s, size_t n, LyXFont const & f); /// return the width of the char in the font - inline int width(char c, LyXFont const & f) { + inline int width(lyx::char_type c, LyXFont const & f) { return width(&c, 1, f); } /// return the width of the string in the font diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index a2da9e221d..2b9f73dbea 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -181,7 +181,7 @@ void QLPainter::text(int x, int y, string const & s, LyXFont const & f) } -void QLPainter::text(int x, int y, char c, LyXFont const & f) +void QLPainter::text(int x, int y, lyx::char_type c, LyXFont const & f) { char s[2] = { c, '\0' }; return text(x, y, s, 1, f); diff --git a/src/frontends/qt2/qfont_metrics.C b/src/frontends/qt2/qfont_metrics.C index ddf640b6fa..1091636c71 100644 --- a/src/frontends/qt2/qfont_metrics.C +++ b/src/frontends/qt2/qfont_metrics.C @@ -18,6 +18,7 @@ #include "language.h" +using lyx::char_type; using std::string; @@ -42,7 +43,7 @@ int maxDescent(LyXFont const & f) } -int ascent(char c, LyXFont const & f) +int ascent(char_type c, LyXFont const & f) { if (!lyx_gui::use_gui) return 1; @@ -58,7 +59,7 @@ int ascent(char c, LyXFont const & f) } -int descent(char c, LyXFont const & f) +int descent(char_type c, LyXFont const & f) { if (!lyx_gui::use_gui) return 1; @@ -74,7 +75,7 @@ int descent(char c, LyXFont const & f) } -int lbearing(char c, LyXFont const & f) +int lbearing(char_type c, LyXFont const & f) { if (!lyx_gui::use_gui) return 1; @@ -82,7 +83,7 @@ int lbearing(char c, LyXFont const & f) } -int rbearing(char c, LyXFont const & f) +int rbearing(char_type c, LyXFont const & f) { if (!lyx_gui::use_gui) return 1; diff --git a/src/lyxtext.h b/src/lyxtext.h index 14fa58b3cf..dbb957d774 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -108,7 +108,7 @@ public: std::string getStringToIndex(LCursor const & cur); /// insert a character at cursor position - void insertChar(LCursor & cur, char c); + void insertChar(LCursor & cur, lyx::char_type c); /// insert an inset at cursor position void insertInset(LCursor & cur, InsetBase * inset); diff --git a/src/paragraph.C b/src/paragraph.C index 7b9ca795fc..47ced728e2 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1816,11 +1816,11 @@ unsigned char Paragraph::transformChar(unsigned char c, pos_type pos) const else return c; - unsigned char const prev_char = pos > 0 ? getChar(pos - 1) : ' '; - unsigned char next_char = ' '; + value_type const prev_char = pos > 0 ? getChar(pos - 1) : ' '; + value_type next_char = ' '; for (pos_type i = pos + 1, end = size(); i < end; ++i) { - unsigned char const par_char = getChar(i); + value_type const par_char = getChar(i); if (!Encodings::isComposeChar_arabic(par_char)) { next_char = par_char; break; diff --git a/src/paragraph.h b/src/paragraph.h index f3c3700025..29d499a267 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -70,9 +70,10 @@ public: /// try getInset() and crash. We should fix /// all these places. META_INSET = 1 + //META_INSET = 0x200001 // above 0x10ffff, for ucs-4 }; /// - typedef char value_type; + typedef lyx::char_type value_type; /// typedef lyx::depth_type depth_type; /// diff --git a/src/rowpainter.C b/src/rowpainter.C index c49721ef08..5971b39d46 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -42,6 +42,7 @@ #include +using lyx::char_type; using lyx::pos_type; using lyx::pit_type; @@ -186,7 +187,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font) string str; // first char - char c = par_.getChar(pos); + char_type c = par_.getChar(pos); str += c; ++vpos; @@ -219,7 +220,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font) string str; // first char - char c = par_.getChar(pos); + char_type c = par_.getChar(pos); c = par_.transformChar(c, pos); str += c; ++vpos; @@ -268,7 +269,7 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font, if (prev_change != par_.lookupChange(pos)) break; - char c = par_.getChar(pos); + char_type c = par_.getChar(pos); if (!isPrintableNonspace(c)) break; @@ -327,7 +328,7 @@ void RowPainter::paintFromPos(pos_type & vpos) } // usual characters, no insets - char const c = par_.getChar(pos); + char_type const c = par_.getChar(pos); // special case languages std::string const & lang = orig_font.language()->lang(); diff --git a/src/support/types.h b/src/support/types.h index cb1de177ac..48fc219e8f 100644 --- a/src/support/types.h +++ b/src/support/types.h @@ -20,6 +20,12 @@ namespace lyx { + // The type used to hold characters in paragraphs + //typedef uint32_t char_type; // Possibly the ucs-4 type we will use + //typedef wchar_t char_type; // The wide char type CJK-LyX uses + typedef char char_type; // Current narrow char type in use + + /// a type for positions used in paragraphs // needs to be signed for a while to hold the special value -1 that is // used there diff --git a/src/text.C b/src/text.C index 937463fedd..82b0928288 100644 --- a/src/text.C +++ b/src/text.C @@ -75,6 +75,7 @@ #include +using lyx::char_type; using lyx::pit_type; using lyx::pos_type; using lyx::word_location; @@ -424,7 +425,7 @@ int LyXText::singleWidth(Paragraph const & par, pos_type pos) const int LyXText::singleWidth(Paragraph const & par, - pos_type pos, char c, LyXFont const & font) const + pos_type pos, char_type c, LyXFont const & font) const { // The most common case is handled first (Asger) if (isPrintable(c)) { @@ -710,7 +711,7 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const pos_type point = end; pos_type i = pos; for ( ; i < end; ++i, ++fi) { - char const c = par.getChar(i); + char_type const c = par.getChar(i); int thiswidth = singleWidth(par, i, c, *fi); // add the auto-hfill from label end to the body @@ -803,7 +804,7 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const w -= singleWidth(par, i - 1); w = max(w, labelEnd(pit)); } - char const c = par.getChar(i); + char_type const c = par.getChar(i); w += singleWidth(par, i, c, *fi); } } @@ -1112,7 +1113,7 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) // insert a character, moves all the following breaks in the // same Paragraph one to the right and make a rebreak -void LyXText::insertChar(LCursor & cur, char c) +void LyXText::insertChar(LCursor & cur, char_type c) { BOOST_ASSERT(this == cur.text()); BOOST_ASSERT(c != Paragraph::META_INSET); @@ -1145,7 +1146,7 @@ void LyXText::insertChar(LCursor & cur, char c) number(cur); // Set current_font.number to ON if (cur.pos() != 0) { - char const c = par.getChar(cur.pos() - 1); + char_type const c = par.getChar(cur.pos() - 1); if (contains(number_unary_operators, c) && (cur.pos() == 1 || par.isSeparator(cur.pos() - 2) @@ -1552,7 +1553,7 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action) pos = 0; continue; } - unsigned char c = pars_[pit].getChar(pos); + char_type c = pars_[pit].getChar(pos); if (c != Paragraph::META_INSET) { switch (action) { case text_lowercase: diff --git a/src/text3.C b/src/text3.C index bf2b02d25b..2c51c5153e 100644 --- a/src/text3.C +++ b/src/text3.C @@ -965,7 +965,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) lyx::cap::replaceSelection(cur); Paragraph & par = cur.paragraph(); lyx::pos_type pos = cur.pos(); - char c; + lyx::char_type c; if (pos == 0) c = ' '; else if (cur.prevInset() && cur.prevInset()->isSpace())