Changeset - r20953:64db27cf67a7
[Not reviewed]
master
0 3 0
rubidium - 11 years ago 2013-11-16 21:05:26
rubidium@openttd.org
(svn r26018) -Codechange: since there's a wrapper for ICU functions now, we can use proper coding style for names again
3 files changed with 85 insertions and 85 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -341,10 +341,10 @@ static void SetColourRemap(TextColour co
 
 */
 
static int DrawLayoutLine(const ParagraphLayouter::Line *line, int y, int left, int right, StringAlignment align, bool underline, bool truncation)
 
{
 
	if (line->countRuns() == 0) return 0;
 
	if (line->CountRuns() == 0) return 0;
 

	
 
	int w = line->getWidth();
 
	int h = line->getLeading();
 
	int w = line->GetWidth();
 
	int h = line->GetLeading();
 

	
 
	/*
 
	 * The following is needed for truncation.
 
@@ -375,7 +375,7 @@ static int DrawLayoutLine(const Paragrap
 
		 * another size would be chosen it won't have truncated too little for
 
		 * the truncation dots.
 
		 */
 
		FontCache *fc = ((const Font*)line->getVisualRun(0)->getFont())->fc;
 
		FontCache *fc = ((const Font*)line->GetVisualRun(0)->GetFont())->fc;
 
		GlyphID dot_glyph = fc->MapCharToGlyph('.');
 
		dot_width = fc->GetGlyphWidth(dot_glyph);
 
		dot_sprite = fc->GetGlyph(dot_glyph);
 
@@ -418,9 +418,9 @@ static int DrawLayoutLine(const Paragrap
 
			NOT_REACHED();
 
	}
 

	
 
	for (int run_index = 0; run_index < line->countRuns(); run_index++) {
 
		const ParagraphLayouter::VisualRun *run = line->getVisualRun(run_index);
 
		const Font *f = (const Font*)run->getFont();
 
	for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
 
		const ParagraphLayouter::VisualRun *run = line->GetVisualRun(run_index);
 
		const Font *f = (const Font*)run->GetFont();
 

	
 
		FontCache *fc = f->fc;
 
		TextColour colour = f->colour;
 
@@ -432,15 +432,15 @@ static int DrawLayoutLine(const Paragrap
 

	
 
		bool draw_shadow = fc->GetDrawGlyphShadow() && colour != TC_BLACK;
 

	
 
		for (int i = 0; i < run->getGlyphCount(); i++) {
 
			GlyphID glyph = run->getGlyphs()[i];
 
		for (int i = 0; i < run->GetGlyphCount(); i++) {
 
			GlyphID glyph = run->GetGlyphs()[i];
 

	
 
			/* Not a valid glyph (empty) */
 
			if (glyph == 0xFFFF) continue;
 

	
 
			int begin_x = (int)run->getPositions()[i * 2]     + left - offset_x;
 
			int end_x   = (int)run->getPositions()[i * 2 + 2] + left - offset_x  - 1;
 
			int top     = (int)run->getPositions()[i * 2 + 1] + y;
 
			int begin_x = (int)run->GetPositions()[i * 2]     + left - offset_x;
 
			int end_x   = (int)run->GetPositions()[i * 2 + 2] + left - offset_x  - 1;
 
			int top     = (int)run->GetPositions()[i * 2 + 1] + y;
 

	
 
			/* Truncated away. */
 
			if (truncation && (begin_x < min_x || end_x > max_x)) continue;
 
@@ -643,7 +643,7 @@ int DrawStringMultiLine(int left, int ri
 
	for (const ParagraphLayouter::Line **iter = layout.Begin(); iter != layout.End(); iter++) {
 
		const ParagraphLayouter::Line *line = *iter;
 

	
 
		int line_height = line->getLeading();
 
		int line_height = line->GetLeading();
 
		if (y >= top && y < bottom) {
 
			last_line = y + line_height;
 
			if (first_line > y) first_line = y;
src/gfx_layout.cpp
Show inline comments
 
@@ -138,12 +138,12 @@ public:
 
	public:
 
		ICUVisualRun(const ParagraphLayout::VisualRun *vr) : vr(vr) { }
 

	
 
		const Font *getFont() const          { return (const Font*)vr->getFont(); }
 
		int getGlyphCount() const            { return vr->getGlyphCount(); }
 
		const GlyphID *getGlyphs() const     { return vr->getGlyphs(); }
 
		const float *getPositions() const    { return vr->getPositions(); }
 
		int getLeading() const               { return vr->getLeading(); }
 
		const int *getGlyphToCharMap() const { return vr->getGlyphToCharMap(); }
 
		const Font *GetFont() const          { return (const Font*)vr->getFont(); }
 
		int GetGlyphCount() const            { return vr->getGlyphCount(); }
 
		const GlyphID *GetGlyphs() const     { return vr->getGlyphs(); }
 
		const float *GetPositions() const    { return vr->getPositions(); }
 
		int GetLeading() const               { return vr->getLeading(); }
 
		const int *GetGlyphToCharMap() const { return vr->getGlyphToCharMap(); }
 
	};
 

	
 
	/** A single line worth of VisualRuns. */
 
@@ -159,17 +159,17 @@ public:
 
		}
 
		~ICULine() { delete l; }
 

	
 
		int getLeading() const { return l->getLeading(); }
 
		int getWidth() const   { return l->getWidth(); }
 
		int countRuns() const  { return l->countRuns(); }
 
		const ParagraphLayouter::VisualRun *getVisualRun(int run) const { return *this->Get(run); }
 
		int GetLeading() const { return l->getLeading(); }
 
		int GetWidth() const   { return l->getWidth(); }
 
		int CountRuns() const  { return l->countRuns(); }
 
		const ParagraphLayouter::VisualRun *GetVisualRun(int run) const { return *this->Get(run); }
 
	};
 

	
 
	ICUParagraphLayout(ParagraphLayout *p) : p(p) { }
 
	~ICUParagraphLayout() { delete p; }
 
	void reflow() { p->reflow(); }
 
	void Reflow() { p->reflow(); }
 

	
 
	ParagraphLayouter::Line *nextLine(int max_width)
 
	ParagraphLayouter::Line *NextLine(int max_width)
 
	{
 
		ParagraphLayout::Line *l = p->nextLine(max_width);
 
		return l == NULL ? NULL : new ICULine(l);
 
@@ -244,21 +244,21 @@ public:
 
	public:
 
		FallbackVisualRun(Font *font, const WChar *chars, int glyph_count, int x);
 
		~FallbackVisualRun();
 
		const Font *getFont() const;
 
		int getGlyphCount() const;
 
		const GlyphID *getGlyphs() const;
 
		const float *getPositions() const;
 
		int getLeading() const;
 
		const int *getGlyphToCharMap() const;
 
		const Font *GetFont() const;
 
		int GetGlyphCount() const;
 
		const GlyphID *GetGlyphs() const;
 
		const float *GetPositions() const;
 
		int GetLeading() const;
 
		const int *GetGlyphToCharMap() const;
 
	};
 

	
 
	/** A single line worth of VisualRuns. */
 
	class FallbackLine : public AutoDeleteSmallVector<FallbackVisualRun *, 4>, public ParagraphLayouter::Line {
 
	public:
 
		int getLeading() const;
 
		int getWidth() const;
 
		int countRuns() const;
 
		const ParagraphLayouter::VisualRun *getVisualRun(int run) const;
 
		int GetLeading() const;
 
		int GetWidth() const;
 
		int CountRuns() const;
 
		const ParagraphLayouter::VisualRun *GetVisualRun(int run) const;
 
	};
 

	
 
	const WChar *buffer_begin; ///< Begin of the buffer.
 
@@ -266,8 +266,8 @@ public:
 
	FontMap &runs;             ///< The fonts we have to use for this paragraph.
 

	
 
	FallbackParagraphLayout(WChar *buffer, int length, FontMap &runs);
 
	void reflow();
 
	const ParagraphLayouter::Line *nextLine(int max_width);
 
	void Reflow();
 
	const ParagraphLayouter::Line *NextLine(int max_width);
 
};
 

	
 
/**
 
@@ -308,7 +308,7 @@ FallbackParagraphLayout::FallbackVisualR
 
 * Get the font associated with this run.
 
 * @return The font.
 
 */
 
const Font *FallbackParagraphLayout::FallbackVisualRun::getFont() const
 
const Font *FallbackParagraphLayout::FallbackVisualRun::GetFont() const
 
{
 
	return this->font;
 
}
 
@@ -317,7 +317,7 @@ const Font *FallbackParagraphLayout::Fal
 
 * Get the number of glyphs in this run.
 
 * @return The number of glyphs.
 
 */
 
int FallbackParagraphLayout::FallbackVisualRun::getGlyphCount() const
 
int FallbackParagraphLayout::FallbackVisualRun::GetGlyphCount() const
 
{
 
	return this->glyph_count;
 
}
 
@@ -326,7 +326,7 @@ int FallbackParagraphLayout::FallbackVis
 
 * Get the glyphs of this run.
 
 * @return The glyphs.
 
 */
 
const GlyphID *FallbackParagraphLayout::FallbackVisualRun::getGlyphs() const
 
const GlyphID *FallbackParagraphLayout::FallbackVisualRun::GetGlyphs() const
 
{
 
	return this->glyphs;
 
}
 
@@ -335,7 +335,7 @@ const GlyphID *FallbackParagraphLayout::
 
 * Get the positions of this run.
 
 * @return The positions.
 
 */
 
const float *FallbackParagraphLayout::FallbackVisualRun::getPositions() const
 
const float *FallbackParagraphLayout::FallbackVisualRun::GetPositions() const
 
{
 
	return this->positions;
 
}
 
@@ -344,7 +344,7 @@ const float *FallbackParagraphLayout::Fa
 
 * Get the glyph-to-character map for this visual run.
 
 * @return The glyph-to-character map.
 
 */
 
const int *FallbackParagraphLayout::FallbackVisualRun::getGlyphToCharMap() const
 
const int *FallbackParagraphLayout::FallbackVisualRun::GetGlyphToCharMap() const
 
{
 
	return this->glyph_to_char;
 
}
 
@@ -353,20 +353,20 @@ const int *FallbackParagraphLayout::Fall
 
 * Get the height of this font.
 
 * @return The height of the font.
 
 */
 
int FallbackParagraphLayout::FallbackVisualRun::getLeading() const
 
int FallbackParagraphLayout::FallbackVisualRun::GetLeading() const
 
{
 
	return this->getFont()->fc->GetHeight();
 
	return this->GetFont()->fc->GetHeight();
 
}
 

	
 
/**
 
 * Get the height of the line.
 
 * @return The maximum height of the line.
 
 */
 
int FallbackParagraphLayout::FallbackLine::getLeading() const
 
int FallbackParagraphLayout::FallbackLine::GetLeading() const
 
{
 
	int leading = 0;
 
	for (const FallbackVisualRun * const *run = this->Begin(); run != this->End(); run++) {
 
		leading = max(leading, (*run)->getLeading());
 
		leading = max(leading, (*run)->GetLeading());
 
	}
 

	
 
	return leading;
 
@@ -376,7 +376,7 @@ int FallbackParagraphLayout::FallbackLin
 
 * Get the width of this line.
 
 * @return The width of the line.
 
 */
 
int FallbackParagraphLayout::FallbackLine::getWidth() const
 
int FallbackParagraphLayout::FallbackLine::GetWidth() const
 
{
 
	if (this->Length() == 0) return 0;
 

	
 
@@ -385,15 +385,15 @@ int FallbackParagraphLayout::FallbackLin
 
	 * Since there is no left-to-right support, taking this value of
 
	 * the last run gives us the end of the line and thus the width.
 
	 */
 
	const ParagraphLayouter::VisualRun *run = this->getVisualRun(this->countRuns() - 1);
 
	return (int)run->getPositions()[run->getGlyphCount() * 2];
 
	const ParagraphLayouter::VisualRun *run = this->GetVisualRun(this->CountRuns() - 1);
 
	return (int)run->GetPositions()[run->GetGlyphCount() * 2];
 
}
 

	
 
/**
 
 * Get the number of runs in this line.
 
 * @return The number of runs.
 
 */
 
int FallbackParagraphLayout::FallbackLine::countRuns() const
 
int FallbackParagraphLayout::FallbackLine::CountRuns() const
 
{
 
	return this->Length();
 
}
 
@@ -402,7 +402,7 @@ int FallbackParagraphLayout::FallbackLin
 
 * Get a specific visual run.
 
 * @return The visual run.
 
 */
 
const ParagraphLayouter::VisualRun *FallbackParagraphLayout::FallbackLine::getVisualRun(int run) const
 
const ParagraphLayouter::VisualRun *FallbackParagraphLayout::FallbackLine::GetVisualRun(int run) const
 
{
 
	return *this->Get(run);
 
}
 
@@ -421,7 +421,7 @@ FallbackParagraphLayout::FallbackParagra
 
/**
 
 * Reset the position to the start of the paragraph.
 
 */
 
void FallbackParagraphLayout::reflow()
 
void FallbackParagraphLayout::Reflow()
 
{
 
	this->buffer = this->buffer_begin;
 
}
 
@@ -431,7 +431,7 @@ void FallbackParagraphLayout::reflow()
 
 * @param max_width The maximum width of the string.
 
 * @return A Line, or NULL when at the end of the paragraph.
 
 */
 
const ParagraphLayouter::Line *FallbackParagraphLayout::nextLine(int max_width)
 
const ParagraphLayouter::Line *FallbackParagraphLayout::NextLine(int max_width)
 
{
 
	/* Simple idea:
 
	 *  - split a line at a newline character, or at a space where we can break a line.
 
@@ -473,7 +473,7 @@ const ParagraphLayouter::Line *FallbackP
 
		}
 

	
 
		if (this->buffer == next_run) {
 
			int w = l->getWidth();
 
			int w = l->GetWidth();
 
			*l->Append() = new FallbackVisualRun(iter->second, begin, this->buffer - begin, w);
 
			iter++;
 
			assert(iter != this->runs.End());
 
@@ -520,7 +520,7 @@ const ParagraphLayouter::Line *FallbackP
 
	}
 

	
 
	if (l->Length() == 0 || last_char - begin != 0) {
 
		int w = l->getWidth();
 
		int w = l->GetWidth();
 
		*l->Append() = new FallbackVisualRun(iter->second, begin, last_char - begin, w);
 
	}
 
	return l;
 
@@ -641,7 +641,7 @@ Layouter::Layouter(const char *str, int 
 
			/* Line is in cache */
 
			str = lineend + 1;
 
			state = line.state_after;
 
			line.layout->reflow();
 
			line.layout->Reflow();
 
		} else {
 
			/* Line is new, layout it */
 
#ifdef WITH_ICU
 
@@ -661,7 +661,7 @@ Layouter::Layouter(const char *str, int 
 

	
 
		/* Copy all lines into a local cache so we can reuse them later on more easily. */
 
		const ParagraphLayouter::Line *l;
 
		while ((l = line.layout->nextLine(maxw)) != NULL) {
 
		while ((l = line.layout->NextLine(maxw)) != NULL) {
 
			*this->Append() = l;
 
		}
 

	
 
@@ -676,8 +676,8 @@ Dimension Layouter::GetBounds()
 
{
 
	Dimension d = { 0, 0 };
 
	for (const ParagraphLayouter::Line **l = this->Begin(); l != this->End(); l++) {
 
		d.width = max<uint>(d.width, (*l)->getWidth());
 
		d.height += (*l)->getLeading();
 
		d.width = max<uint>(d.width, (*l)->GetWidth());
 
		d.height += (*l)->GetLeading();
 
	}
 
	return d;
 
}
 
@@ -713,18 +713,18 @@ Point Layouter::GetCharPosition(const ch
 

	
 
		/* Pointer to the end-of-string/line marker? Return total line width. */
 
		if (*ch == '\0' || *ch == '\n') {
 
			Point p = { line->getWidth(), 0 };
 
			Point p = { line->GetWidth(), 0 };
 
			return p;
 
		}
 

	
 
		/* Scan all runs until we've found our code point index. */
 
		for (int run_index = 0; run_index < line->countRuns(); run_index++) {
 
			const ParagraphLayouter::VisualRun *run = line->getVisualRun(run_index);
 
		for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
 
			const ParagraphLayouter::VisualRun *run = line->GetVisualRun(run_index);
 

	
 
			for (int i = 0; i < run->getGlyphCount(); i++) {
 
			for (int i = 0; i < run->GetGlyphCount(); i++) {
 
				/* Matching glyph? Return position. */
 
				if ((size_t)run->getGlyphToCharMap()[i] == index) {
 
					Point p = { (int)run->getPositions()[i * 2], (int)run->getPositions()[i * 2 + 1] };
 
				if ((size_t)run->GetGlyphToCharMap()[i] == index) {
 
					Point p = { (int)run->GetPositions()[i * 2], (int)run->GetPositions()[i * 2 + 1] };
 
					return p;
 
				}
 
			}
 
@@ -742,21 +742,21 @@ Point Layouter::GetCharPosition(const ch
 
 */
 
const char *Layouter::GetCharAtPosition(int x) const
 
{
 
	const ParagraphLayouter::Line *line = *this->Begin();;
 
	const ParagraphLayouter::Line *line = *this->Begin();
 

	
 
	for (int run_index = 0; run_index < line->countRuns(); run_index++) {
 
		const ParagraphLayouter::VisualRun *run = line->getVisualRun(run_index);
 
	for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
 
		const ParagraphLayouter::VisualRun *run = line->GetVisualRun(run_index);
 

	
 
		for (int i = 0; i < run->getGlyphCount(); i++) {
 
		for (int i = 0; i < run->GetGlyphCount(); i++) {
 
			/* Not a valid glyph (empty). */
 
			if (run->getGlyphs()[i] == 0xFFFF) continue;
 
			if (run->GetGlyphs()[i] == 0xFFFF) continue;
 

	
 
			int begin_x = (int)run->getPositions()[i * 2];
 
			int end_x   = (int)run->getPositions()[i * 2 + 2];
 
			int begin_x = (int)run->GetPositions()[i * 2];
 
			int end_x   = (int)run->GetPositions()[i * 2 + 2];
 

	
 
			if (IsInsideMM(x, begin_x, end_x)) {
 
				/* Found our glyph, now convert to UTF-8 string index. */
 
				size_t index = run->getGlyphToCharMap()[i];
 
				size_t index = run->GetGlyphToCharMap()[i];
 

	
 
				size_t cur_idx = 0;
 
				for (const char *str = this->string; *str != '\0'; ) {
src/gfx_layout.h
Show inline comments
 
@@ -108,26 +108,26 @@ public:
 
	class VisualRun {
 
	public:
 
		virtual ~VisualRun() {}
 
		virtual const Font *getFont() const = 0;
 
		virtual int getGlyphCount() const = 0;
 
		virtual const GlyphID *getGlyphs() const = 0;
 
		virtual const float *getPositions() const = 0;
 
		virtual int getLeading() const = 0;
 
		virtual const int *getGlyphToCharMap() const = 0;
 
		virtual const Font *GetFont() const = 0;
 
		virtual int GetGlyphCount() const = 0;
 
		virtual const GlyphID *GetGlyphs() const = 0;
 
		virtual const float *GetPositions() const = 0;
 
		virtual int GetLeading() const = 0;
 
		virtual const int *GetGlyphToCharMap() const = 0;
 
	};
 

	
 
	/** A single line worth of VisualRuns. */
 
	class Line {
 
	public:
 
		virtual ~Line() {}
 
		virtual int getLeading() const = 0;
 
		virtual int getWidth() const = 0;
 
		virtual int countRuns() const = 0;
 
		virtual const VisualRun *getVisualRun(int run) const = 0;
 
		virtual int GetLeading() const = 0;
 
		virtual int GetWidth() const = 0;
 
		virtual int CountRuns() const = 0;
 
		virtual const VisualRun *GetVisualRun(int run) const = 0;
 
	};
 

	
 
	virtual void reflow() = 0;
 
	virtual const Line *nextLine(int max_width) = 0;
 
	virtual void Reflow() = 0;
 
	virtual const Line *NextLine(int max_width) = 0;
 
};
 

	
 
/**
0 comments (0 inline, 0 general)