Fix some unicode conversion problems, more work needed.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15442 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2006-10-21 11:15:37 +00:00
parent 6ac15c5bb9
commit d12c1f4b22
11 changed files with 52 additions and 21 deletions

View File

@ -22,6 +22,7 @@ namespace lyx {
using std::string;
using std::auto_ptr;
using std::vector;
InsetMathExFunc::InsetMathExFunc(string const & name)
@ -45,7 +46,8 @@ auto_ptr<InsetBase> InsetMathExFunc::doClone() const
void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & /*dim*/) const
{
// FIXME UNICODE
mathed_string_dim(mi.base.font, from_utf8(name_), dim_);
vector<char_type> n(name_.begin(), name_.end());
mathed_string_dim(mi.base.font, n, dim_);
}

View File

@ -30,6 +30,7 @@ using std::string;
using std::max;
using std::auto_ptr;
using std::endl;
using std::vector;
MathMacro::MathMacro(string const & name, int numargs)
@ -61,7 +62,9 @@ void MathMacro::cursorPos(BufferView const & bv,
void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (!MacroTable::globalMacros().has(name())) {
mathed_string_dim(mi.base.font, from_utf8("Unknown: " + name()), dim);
string t = "Unknown: " + name();
vector<char_type> n(t.begin(), t.end());
mathed_string_dim(mi.base.font, n, dim);
} else if (editing(mi.base.bv)) {
// FIXME UNICODE
asArray(from_utf8(MacroTable::globalMacros().get(name()).def()), tmpl_);
@ -103,7 +106,9 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
tmpl_.draw(pi, x + w + 12, h);
h += tmpl_.descent();
Dimension ldim;
mathed_string_dim(font, from_ascii("#1: "), ldim);
string t = "#1: ";
vector<char_type> n(t.begin(), t.end());
mathed_string_dim(font, n, ldim);
for (idx_type i = 0; i < nargs(); ++i) {
MathArray const & c = cell(i);
h += max(c.ascent(), ldim.asc) + 5;

View File

@ -20,7 +20,7 @@ namespace lyx {
using std::string;
using std::auto_ptr;
using std::vector;
InsetMathNumber::InsetMathNumber(string const & s)
: str_(s)
@ -36,7 +36,8 @@ auto_ptr<InsetBase> InsetMathNumber::doClone() const
void InsetMathNumber::metrics(MetricsInfo & mi, Dimension & dim) const
{
// FIXME UNICODE
mathed_string_dim(mi.base.font, from_utf8(str_), dim);
vector<char_type> n(str_.begin(), str_.end());
mathed_string_dim(mi.base.font, n, dim);
}

View File

@ -20,6 +20,7 @@ namespace lyx {
using std::string;
using std::auto_ptr;
using std::vector;
InsetMathString::InsetMathString(string const & s)
@ -36,7 +37,8 @@ auto_ptr<InsetBase> InsetMathString::doClone() const
void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const
{
// FIXME UNICODE
mathed_string_dim(mi.base.font, from_utf8(str_), dim);
vector<char_type> n(str_.begin(), str_.end());
mathed_string_dim(mi.base.font, n, dim);
}

View File

@ -64,7 +64,7 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
int const em = mathed_char_width(mi.base.font, 'M');
FontSetChanger dummy(mi.base, sym_->inset.c_str());
// FIXME UNICODE
mathed_string_dim(mi.base.font, from_utf8(sym_->draw), dim);
mathed_string_dim(mi.base.font, sym_->draw, dim);
// correct height for broken cmex and wasy font
#if defined(__APPLE__) && defined(__GNUC__)
if (sym_->inset == "cmex") {
@ -113,7 +113,8 @@ void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
FontSetChanger dummy(pi.base, sym_->inset.c_str());
// FIXME UNICODE
pi.draw(x, y - h_, from_utf8(sym_->draw));
docstring n(sym_->draw.begin(), sym_->draw.end());
pi.draw(x, y - h_, n);
}

View File

@ -21,6 +21,7 @@ namespace lyx {
using std::string;
using std::auto_ptr;
using std::vector;
InsetMathUnknown::InsetMathUnknown(string const & nm, bool final, bool black)
@ -55,7 +56,8 @@ void InsetMathUnknown::normalize(NormalStream & os) const
void InsetMathUnknown::metrics(MetricsInfo & mi, Dimension & dim) const
{
// FIXME UNICODE
mathed_string_dim(mi.base.font, from_utf8(name_), dim);
vector<char_type> n(name_.begin(), name_.end());
mathed_string_dim(mi.base.font, n, dim);
dim_ = dim;
}

View File

@ -74,6 +74,7 @@ using support::split;
using std::string;
using std::endl;
using std::istringstream;
using std::vector;
bool has_math_fonts;
@ -179,20 +180,25 @@ void initSymbols()
if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra == "special") {
lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << endl;
tmp.draw = tmp.name;
// FIXME UNICODE
vector<char_type> n(tmp.name.begin(), tmp.name.end());
tmp.draw = n;
} else if (math_font_available(tmp.inset)) {
lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << endl;
tmp.draw += char(charid);
tmp.draw.push_back(char_type(charid));
} else if (fallbackid && math_font_available(symbol_font)) {
if (tmp.inset == "cmex")
tmp.inset = "lyxsymbol";
else
tmp.inset = "lyxboldsymbol";
lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << endl;
tmp.draw += char(fallbackid);
tmp.draw.push_back(char_type(fallbackid));
} else {
lyxerr[Debug::MATHED] << "faking " << tmp.name << endl;
tmp.draw = tmp.name;
vector<char_type> n(tmp.name.begin(),
tmp.name.end());
tmp.draw = n;
tmp.inset = "lyxtex";
}
} else {

View File

@ -23,6 +23,7 @@ namespace lyx {
using std::endl;
using std::auto_ptr;
using std::size_t;
using std::vector;
MathMacroArgument::MathMacroArgument(size_t n)
@ -52,7 +53,8 @@ void MathMacroArgument::write(WriteStream & os) const
void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, from_utf8(str_), dim_);
vector<char_type> n(str_, str_ + 3);
mathed_string_dim(mi.base.font, n, dim_);
dim = dim_;
}

View File

@ -13,8 +13,10 @@
#ifndef MATH_PARSER_H
#define MATH_PARSER_H
#include <string>
#include "support/types.h"
#include <string>
#include <vector>
namespace lyx {
@ -33,7 +35,7 @@ public:
/// name of a inset that handles that macro
std::string inset;
/// position of the ting in a font
std::string draw;
std::vector<char_type> draw;
/// operator/..., fontname e
std::string extra;
/// how is this called as XML entity?

View File

@ -35,6 +35,7 @@ using frontend::Painter;
using std::string;
using std::max;
using std::endl;
using std::vector;
///
@ -382,16 +383,20 @@ int mathed_char_width(LyXFont const & font, char_type c)
}
void mathed_string_dim(LyXFont const & font, docstring const & s, Dimension & dim)
void mathed_string_dim(LyXFont const & font,
vector<char_type> const & s,
Dimension & dim)
{
frontend::FontMetrics const & fm = theFontMetrics(font);
dim.asc = 0;
dim.des = 0;
for (docstring::const_iterator it = s.begin(); it != s.end(); ++it) {
for (vector<char_type>::const_iterator it = s.begin();
it != s.end();
++it) {
dim.asc = max(dim.asc, fm.ascent(*it));
dim.des = max(dim.des, fm.descent(*it));
}
dim.wid = fm.width(s);
dim.wid = fm.width(&s[0], s.size());
}

View File

@ -16,7 +16,7 @@
#include "support/docstring.h"
#include <string>
#include <vector>
namespace lyx {
@ -34,7 +34,10 @@ int mathed_char_width(LyXFont const &, char_type c);
void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
std::string const & name);
void mathed_string_dim(LyXFont const & font, docstring const & s, Dimension & dim);
void mathed_string_dim(LyXFont const & font,
std::vector<char_type> const & s,
Dimension & dim);
int mathed_string_width(LyXFont const &, docstring const & s);
void drawStrRed(PainterInfo & pi, int x, int y, docstring const & s);