Sha256: fb6a59fe036ff0b3a5572328bca5e8a153bab17600276c6c85f77b34acc0dcd6

Contents?: true

Size: 1.75 KB

Versions: 34

Compression:

Stored size: 1.75 KB

Contents

#include "font.h"


#include <assert.h>


namespace Rays
{


	struct Font::Data
	{

		RawFont rawfont;

		mutable RawFont rawfont_for_pixel_density;

		mutable float for_pixel_density = 1;

		const RawFont& get_raw (float pixel_density) const
		{
			assert(pixel_density > 0);

			if (!rawfont || pixel_density == 1)
				return rawfont;

			if (pixel_density != for_pixel_density)
			{
				rawfont_for_pixel_density =
					RawFont(rawfont.name(), rawfont.size() * pixel_density);
				for_pixel_density = pixel_density;
			}

			return rawfont_for_pixel_density;
		}

	};// Font::Data


	const Font&
	default_font ()
	{
		static const Font FONT(NULL);
		return FONT;
	}

	const RawFont&
	Font_get_raw (const Font& font, float pixel_density)
	{
		return font.self->get_raw(pixel_density);
	}

	coord
	Font_get_width (const Font& font, float pixel_density, const char* str)
	{
		return Font_get_raw(font, pixel_density).get_width(str);
	}

	coord
	Font_get_height (
		const Font& font, float pixel_density,
		coord* ascent, coord* descent, coord* leading)
	{
		return Font_get_raw(font, pixel_density)
			.get_height(ascent, descent, leading);
	}


	Font::Font ()
	{
	}

	Font::Font (const char* name, coord size)
	{
		self->rawfont = RawFont(name, size);
	}

	Font::~Font ()
	{
	}

	String
	Font::name () const
	{
		return self->rawfont.name();
	}

	coord
	Font::size () const
	{
		return self->rawfont.size();
	}

	coord
	Font::get_width (const char* str) const
	{
		return self->rawfont.get_width(str);
	}

	coord
	Font::get_height (coord* ascent, coord* descent, coord* leading) const
	{
		return self->rawfont.get_height(ascent, descent, leading);
	}

	Font::operator bool () const
	{
		return !!self->rawfont;
	}

	bool
	Font::operator ! () const
	{
		return !operator bool();
	}


}// Rays

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
rays-0.1.26 src/font.cpp
rays-0.1.25 src/font.cpp
rays-0.1.24 src/font.cpp
rays-0.1.23 src/font.cpp
rays-0.1.22 src/font.cpp
rays-0.1.21 src/font.cpp
rays-0.1.20 src/font.cpp
rays-0.1.19 src/font.cpp
rays-0.1.18 src/font.cpp
rays-0.1.17 src/font.cpp
rays-0.1.16 src/font.cpp
rays-0.1.15 src/font.cpp
rays-0.1.14 src/font.cpp
rays-0.1.13 src/font.cpp