Example #1
0
void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx)
{
	GuiLock __;
	
	int ascent = font.GetAscent();
	double sina = 0;
	double cosa = 1;
	if(angle)
		Draw::SinCos(angle, sina, cosa);
	int xpos = 0;	
	Buffer<cairo_glyph_t> gs(n);
	for(int i = 0; i < n; i++) {
		cairo_glyph_t& g = gs[i];
		g.index = GetGlyphInfo(font, text[i]).glyphi;
		g.x = fround(x + cosa * xpos + sina * ascent);
		g.y = fround(y + cosa * ascent - sina * xpos);
		xpos += dx ? dx[i] : font[text[i]];
	}

	static LRUCache<FontSysData, Tuple2<Font, int> > cache;
	FontDataSysMaker m;
	m.font = font;
	m.angle = angle;
	FontSysData& sf = cache.Get(m);
	
	cairo_set_scaled_font(cr, sf.scaled_font);

	SetColor(ink);
 	cairo_show_glyphs(cr, gs, n);
 	
 	cache.Shrink(64);
}
Example #2
0
bool SpellWord(const WString& ws, int lang)
{
	speller_cache.Shrink(2000);
	SpellMaker m;
	m.k.lang = lang;
	m.k.wrd = ws;
	return speller_cache.Get(m);
}
Example #3
0
void GLDraw::PutImage(Point p, const Image& img, const Rect& src)
{
	if(img.GetLength() == 0)
		return;

	LLOG("PutImage " << img.GetSerialId() << ' ' << p.x << ", " << p.y << ", "<< img.GetSize());
	LLOG("SysImage cache pixels " << sTextureCache.GetSize() << ", count " << sTextureCache.GetCount());
	ImageGLDataMaker m;
	m.img = img;
	ImageGLData& sd = sTextureCache.Get(m);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, sd.texture_id);
	
	glColor3f(1.0f, 1.0f, 1.0f);
	
	if(src == img.GetSize()) {
		Rect r(p, img.GetSize());
		glBegin(GL_TRIANGLE_STRIP);
			glTexCoord2f(0, 0);
			glVertex2i(r.left, r.top);
			glTexCoord2f(1, 0);
			glVertex2i(r.right, r.top);
			glTexCoord2f(0, 1);
			glVertex2i(r.left, r.bottom);
			glTexCoord2f(1, 1);
			glVertex2i(r.right, r.bottom);
		glEnd();
	}
	else {
		Sizef iszf = img.GetSize();
		Rect s = src & img.GetSize();
		Rect r(p, s.GetSize());
		Rectf h;
		h.left = (double)s.left / iszf.cx;
		h.right = (double)s.right / iszf.cx;
		h.top = (double)s.top / iszf.cy;
		h.bottom = (double)s.bottom / iszf.cy;
		glBegin(GL_TRIANGLE_STRIP);
			glTexCoord2f(h.left, h.top);
			glVertex2i(r.left, r.top);
			glTexCoord2f(h.right, h.top);
			glVertex2i(r.right, r.top);
			glTexCoord2f(h.left, h.bottom);
			glVertex2i(r.left, r.bottom);
			glTexCoord2f(h.right, h.bottom);
			glVertex2i(r.right, r.bottom);
		glEnd();
	}

   	glDisable(GL_TEXTURE_2D);

	sTextureCache.Shrink(4 * 1024 * 768, 1000);
}
Example #4
0
void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color)
{
	GuiLock __;
	if(img.GetLength() == 0)
		return;
	LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize());
	ImageSysDataMaker m;
	static LRUCache<ImageSysData, int64> cache;
	LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
	m.img = img;
	cache.Get(m).Paint(*this, x, y, src, color);
	Size sz = Ctrl::GetPrimaryScreenArea().GetSize();
	cache.Shrink(4 * sz.cx * sz.cy, 1000); // Cache must be after Paint because of PaintOnly!
}
Example #5
0
void Painter::CharacterOp(double x, double y, int ch, Font fnt)
{
	PAINTER_TIMING("CharacterOp");
	String s;
	INTERLOCKED {
		static LRUCache<String, FontChar> cache;
		cache.Shrink(100000);
		sMakeCharOutline h;
		h.fc.fnt = fnt;
		h.fc.chr = ch;
		s = cache.Get(h);
	}
	RenderCharPath(s, s.GetLength(), *this, x, y + fnt.Info().GetAscent());
	EvenOdd(true);
}
Example #6
0
void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, Color color)
{
	GuiLock __;
	if(img.GetLength() == 0)
		return;
	LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << x << ", " << y << ", "<< img.GetSize());
	ImageSysDataMaker m;
	static LRUCache<ImageSysData, int64> cache;
	LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
	m.img = img;
	ImageSysData& sd = cache.Get(m);
	if(!IsNull(color)) {
		SetColor(color);
		cairo_mask_surface(cr, sd.surface, x, y);
	}
	else {
		cairo_set_source_surface(cr, sd.surface, x, y);
		cairo_paint(cr);
	}
	cache.Shrink(4 * 1024 * 768, 1000); // Cache must be after Paint because of PaintOnly!
}
Example #7
0
void BufferPainter::ApproximateChar(LinearPathConsumer& t, const CharData& ch, double tolerance)
{
	PAINTER_TIMING("ApproximateChar");
	Value v;
	INTERLOCKED {
		PAINTER_TIMING("ApproximateChar::Fetch");
		static LRUCache<Value, GlyphKey> cache;
		cache.Shrink(500000);
		sMakeGlyph h;
		h.gk.fnt = ch.fnt;
		h.gk.chr = ch.ch;
		h.gk.tolerance = tolerance;
		v = cache.Get(h);
	}
#if 0
	GlyphPainter chp;
	chp.move = chp.pos = Null;
	chp.tolerance = tolerance;
	PaintCharacter(chp, ch.p, ch.ch, ch.fnt);
	Vector<float>& g = chp.glyph;
#else
	const Vector<float>& g = ValueTo< Vector<float> >(v);
#endif
	int i = 0;
	while(i < g.GetCount()) {
		Pointf p;
		p.x = g[i++];
		if(p.x > 1e30) {
			p.x = g[i++];
			p.y = g[i++];
			t.Move(p + ch.p);
		}
		else {
			PAINTER_TIMING("ApproximateChar::Line");
			p.y = g[i++];
			t.Line(p + ch.p);
		}
	}
}