mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
did a bunch of other stuff, sorry about the monolithic changeset but the diffs should be understandable enough
This commit is contained in:
@@ -50,7 +50,7 @@ namespace font
|
||||
return MAX_CHARS;
|
||||
}
|
||||
|
||||
GlyphData * FontData::getGlyph(unsigned short glyph) const
|
||||
GlyphData * FontData::getGlyphData(unsigned short glyph) const
|
||||
{
|
||||
return data[glyph];
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace font
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
GlyphData * getGlyph(unsigned short glyph) const;
|
||||
GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
int getHeight() const;
|
||||
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
|
||||
@@ -25,10 +25,20 @@ namespace love
|
||||
namespace font
|
||||
{
|
||||
|
||||
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics)
|
||||
: glyph(glyph), metrics(glyphMetrics)
|
||||
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
|
||||
: glyph(glyph), metrics(glyphMetrics), format(f)
|
||||
{
|
||||
data = new unsigned char[getWidth() * getHeight() * 4];
|
||||
if (getWidth() && getHeight()) {
|
||||
switch (f) {
|
||||
case GlyphData::FORMAT_LUMINOSITY_ALPHA:
|
||||
data = new unsigned char[getWidth() * getHeight() * 2];
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
data = new unsigned char[getWidth() * getHeight() * 4];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlyphData::~GlyphData()
|
||||
@@ -43,7 +53,16 @@ namespace font
|
||||
|
||||
int GlyphData::getSize() const
|
||||
{
|
||||
return getWidth() * getHeight() * 4;
|
||||
switch(format) {
|
||||
case GlyphData::FORMAT_LUMINOSITY_ALPHA:
|
||||
return getWidth() * getHeight() * 2;
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
return getWidth() * getHeight() * 4;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int GlyphData::getHeight() const
|
||||
@@ -90,6 +109,11 @@ namespace font
|
||||
{
|
||||
return this->getBearingY();
|
||||
}
|
||||
|
||||
GlyphData::Format GlyphData::getFormat() const
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_FONT_GLYPH_DATA_H
|
||||
@@ -29,16 +29,17 @@ namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
/**
|
||||
* Holds the specific glyph data.
|
||||
**/
|
||||
struct GlyphMetrics
|
||||
{
|
||||
int height;
|
||||
int width;
|
||||
int advance;
|
||||
int bearingX;
|
||||
int bearingY;
|
||||
/**
|
||||
* Holds the specific glyph data.
|
||||
**/
|
||||
struct GlyphMetrics
|
||||
{
|
||||
int height;
|
||||
int width;
|
||||
int advance;
|
||||
int bearingX;
|
||||
int bearingY;
|
||||
int spacing;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -46,22 +47,19 @@ namespace font
|
||||
**/
|
||||
class GlyphData : public Data
|
||||
{
|
||||
private:
|
||||
// The glyph itself
|
||||
unsigned short glyph;
|
||||
|
||||
// Glyph metrics
|
||||
GlyphMetrics metrics;
|
||||
|
||||
// Glyph texture data
|
||||
unsigned char * data;
|
||||
|
||||
public:
|
||||
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics);
|
||||
enum Format
|
||||
{
|
||||
FORMAT_LUMINOSITY_ALPHA,
|
||||
FORMAT_RGBA
|
||||
};
|
||||
|
||||
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, Format f);
|
||||
virtual ~GlyphData();
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
/**
|
||||
@@ -108,6 +106,24 @@ namespace font
|
||||
* Gets the max y value of the glyph.
|
||||
**/
|
||||
int getMaxY() const;
|
||||
|
||||
/**
|
||||
* Gets the format of the glyph data.
|
||||
**/
|
||||
Format getFormat() const;
|
||||
|
||||
private:
|
||||
// The glyph itself
|
||||
unsigned short glyph;
|
||||
|
||||
// Glyph metrics
|
||||
GlyphMetrics metrics;
|
||||
|
||||
// Glyph texture data
|
||||
unsigned char * data;
|
||||
|
||||
// The format the data's in
|
||||
Format format;
|
||||
|
||||
}; // GlyphData
|
||||
|
||||
|
||||
@@ -38,8 +38,11 @@ namespace font
|
||||
{
|
||||
imageData->retain();
|
||||
positions = new unsigned int[MAX_CHARS];
|
||||
memset(positions, 0, MAX_CHARS*4);
|
||||
widths = new unsigned int[MAX_CHARS];
|
||||
memset(widths, 0, MAX_CHARS*4);
|
||||
spacing = new unsigned int[MAX_CHARS];
|
||||
memset(spacing, 0, MAX_CHARS*4);
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -61,11 +64,15 @@ namespace font
|
||||
GlyphMetrics gm;
|
||||
gm.height = metrics.height;
|
||||
gm.width = widths[glyph];
|
||||
GlyphData * g = new GlyphData(glyph, gm);
|
||||
gm.advance = spacing[glyph] + widths[glyph];
|
||||
gm.bearingX = 0;
|
||||
gm.bearingY = 0;
|
||||
GlyphData * g = new GlyphData(glyph, gm, GlyphData::FORMAT_RGBA);
|
||||
if (gm.width == 0) return g;
|
||||
unsigned char * gd = (unsigned char*)g->getData();
|
||||
love::image::pixel * pixels = (love::image::pixel *)(imageData->getData());
|
||||
for (unsigned int i = positions[glyph]; i < positions[glyph] + widths[glyph]; i++) {
|
||||
love::image::pixel p = pixels[i];
|
||||
for (unsigned int i = 0; i < widths[glyph]*getHeight(); i++) {
|
||||
love::image::pixel p = pixels[ positions[glyph] + (i % widths[glyph]) + (imageData->getWidth() * (i / widths[glyph])) ];
|
||||
gd[i*4] = p.r;
|
||||
gd[i*4+1] = p.g;
|
||||
gd[i*4+2] = p.b;
|
||||
@@ -132,6 +139,11 @@ namespace font
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ImageRasterizer::getNumGlyphs() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
@@ -59,6 +59,7 @@ namespace font
|
||||
// Implement Rasterizer
|
||||
virtual int getLineHeight() const;
|
||||
virtual GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
virtual int getNumGlyphs() const;
|
||||
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
|
||||
|
||||
@@ -82,6 +82,11 @@ namespace font
|
||||
* @param glyph The (UNICODE) glyph to get data for
|
||||
**/
|
||||
virtual GlyphData * getGlyphData(unsigned short glyph) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the number of glyphs the rasterizer has data for.
|
||||
**/
|
||||
virtual int getNumGlyphs() const = 0;
|
||||
|
||||
|
||||
}; // Rasterizer
|
||||
|
||||
@@ -46,10 +46,11 @@ namespace freetype
|
||||
FT_Set_Pixel_Sizes(face, size, size);
|
||||
|
||||
// Set global metrics
|
||||
metrics.advance = face->max_advance_width;
|
||||
metrics.ascent = face->ascender;
|
||||
metrics.descent = face->descender;
|
||||
metrics.height = face->height;
|
||||
FT_Size_Metrics s = face->size->metrics;
|
||||
metrics.advance = s.max_advance >> 6;
|
||||
metrics.ascent = s.ascender >> 6;
|
||||
metrics.descent = s.descender >> 6;
|
||||
metrics.height = s.height >> 6;
|
||||
}
|
||||
|
||||
TrueTypeRasterizer::~TrueTypeRasterizer()
|
||||
@@ -80,23 +81,24 @@ namespace freetype
|
||||
FT_Bitmap& bitmap = bitmap_glyph->bitmap; //just to make things easier
|
||||
|
||||
// Get metrics
|
||||
glyphMetrics.bearingX = face->glyph->metrics.horiBearingX;
|
||||
glyphMetrics.bearingY = face->glyph->metrics.horiBearingY;
|
||||
glyphMetrics.bearingX = face->glyph->metrics.horiBearingX >> 6;
|
||||
glyphMetrics.bearingY = face->glyph->metrics.horiBearingY >> 6;
|
||||
glyphMetrics.height = bitmap.rows;
|
||||
glyphMetrics.width = bitmap.width;
|
||||
glyphMetrics.advance = face->glyph->advance.x >> 6;
|
||||
glyphMetrics.advance = face->glyph->metrics.horiAdvance >> 6;
|
||||
|
||||
GlyphData * glyphData = new GlyphData(glyph, glyphMetrics);
|
||||
GlyphData * glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_RGBA);
|
||||
|
||||
{
|
||||
int size = bitmap.rows*bitmap.width;
|
||||
unsigned char * dst = (unsigned char *)glyphData->getData();
|
||||
|
||||
// Note that bitmap.buffer contains only luminosity. We copy that single value to
|
||||
// our rgba format.
|
||||
// our luminosity-alpha format.
|
||||
for(int i = 0; i<size; i++)
|
||||
{
|
||||
dst[4*i] = dst[4*i+1] = dst[4*i+2] = dst[4*i+3] = bitmap.buffer[i];
|
||||
dst[4*i] = dst[4*i+1] = dst[4*i+2] = 255;
|
||||
dst[4*i+3] = bitmap.buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +108,11 @@ namespace freetype
|
||||
// Return data
|
||||
return glyphData;
|
||||
}
|
||||
|
||||
int TrueTypeRasterizer::getNumGlyphs() const
|
||||
{
|
||||
return 256;
|
||||
}
|
||||
|
||||
} // freetype
|
||||
} // font
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace freetype
|
||||
// Implement Rasterizer
|
||||
virtual int getLineHeight() const;
|
||||
virtual GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
virtual int getNumGlyphs() const;
|
||||
|
||||
}; // FreetypeRasterizer
|
||||
|
||||
|
||||
@@ -1,48 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Font.h"
|
||||
|
||||
#include <common/math.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Font::Font(int size)
|
||||
: size(size), lineHeight(1), mSpacing(1)
|
||||
|
||||
Font::Font(love::font::FontData * data)
|
||||
: height(data->getHeight()), lineHeight(1.25)
|
||||
{
|
||||
glyphs = new Glyph*[MAX_CHARS];
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
widths[i] = 0;
|
||||
spacing[i] = 0;
|
||||
glyphs[i] = new Glyph(data->getGlyphData(i));
|
||||
glyphs[i]->load();
|
||||
widths[i] = data->getGlyphData(i)->getWidth();
|
||||
spacing[i] = data->getGlyphData(i)->getAdvance();
|
||||
bearingX[i] = data->getGlyphData(i)->getBearingX();
|
||||
bearingY[i] = data->getGlyphData(i)->getBearingY();
|
||||
}
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
delete[] glyphs;
|
||||
}
|
||||
|
||||
float Font::getHeight() const
|
||||
{
|
||||
return (float)size;
|
||||
return height;
|
||||
}
|
||||
|
||||
void Font::print(std::string text, float x, float y) const
|
||||
{
|
||||
print(text, x, y, 0.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void Font::print(std::string text, float x, float y, float angle, float sx, float sy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(ceil(x), ceil(y+getHeight()), 0.0f);
|
||||
glRotatef(LOVE_TODEG(angle), 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
int s = 0;
|
||||
for (unsigned int i = 0; i < text.size(); i++) {
|
||||
int g = (int)text[i];
|
||||
glyphs[g]->draw(bearingX[g] + s, -bearingY[g], 0, 1, 1, 0, 0);
|
||||
s += spacing[g];
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Font::print(char character, float x, float y) const
|
||||
{
|
||||
glyphs[character]->draw(x, y+getHeight(), 0, 1, 1, 0, 0);
|
||||
}
|
||||
|
||||
float Font::getWidth(const std::string & line) const
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <graphics/Volatile.h>
|
||||
#include <font/FontData.h>
|
||||
#include "Glyph.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -34,33 +35,35 @@ namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class Font : public Object, public Volatile
|
||||
class Font : public Object
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
int size;
|
||||
int height;
|
||||
float lineHeight;
|
||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||
Glyph ** glyphs;
|
||||
|
||||
public:
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
// The widths of each character.
|
||||
int widths[MAX_CHARS];
|
||||
// The spacing of each character.
|
||||
int spacing[MAX_CHARS];
|
||||
// The X-bearing of each character.
|
||||
int bearingX[MAX_CHARS];
|
||||
// The Y-bearing of each character.
|
||||
int bearingY[MAX_CHARS];
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The file containing the OpenGLFont data.
|
||||
* @param size The size of the OpenGLFont.
|
||||
* @param data The font data to construct from.
|
||||
**/
|
||||
Font(int size);
|
||||
Font(love::font::FontData * data);
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
virtual bool load() = 0;
|
||||
virtual void unload() = 0;
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position.
|
||||
*
|
||||
@@ -68,7 +71,7 @@ namespace opengl
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void print(std::string text, float x, float y) const = 0;
|
||||
void print(std::string text, float x, float y) const;
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position with rotation and scaling.
|
||||
@@ -78,7 +81,7 @@ namespace opengl
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
**/
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const = 0;
|
||||
void print(std::string text, float x, float y, float angle, float sx, float sy) const;
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
@@ -87,27 +90,27 @@ namespace opengl
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void print(char character, float x, float y) const = 0;
|
||||
void print(char character, float x, float y) const;
|
||||
|
||||
/**
|
||||
* Returns the height of the font.
|
||||
**/
|
||||
virtual float getHeight() const;
|
||||
float getHeight() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed string.
|
||||
*
|
||||
* @param line A line of text.
|
||||
**/
|
||||
virtual float getWidth(const std::string & line) const;
|
||||
virtual float getWidth(const char * line) const;
|
||||
float getWidth(const std::string & line) const;
|
||||
float getWidth(const char * line) const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed character.
|
||||
*
|
||||
* @param character A character.
|
||||
**/
|
||||
virtual float getWidth(const char character) const;
|
||||
float getWidth(const char character) const;
|
||||
|
||||
/**
|
||||
* Sets the line height (which should be a number to multiply the font size by,
|
||||
@@ -119,7 +122,7 @@ namespace opengl
|
||||
/**
|
||||
* Returns the line height.
|
||||
**/
|
||||
virtual float getLineHeight() const;
|
||||
float getLineHeight() const;
|
||||
|
||||
/**
|
||||
* Sets the spacing modifier (changes the spacing between the characters the
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace opengl
|
||||
: data(data), width((float)data->getWidth()), height((float)data->getHeight()), texture(0)
|
||||
{
|
||||
data->retain();
|
||||
data->getWidth();
|
||||
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
@@ -94,6 +93,9 @@ namespace opengl
|
||||
|
||||
bool Glyph::loadVolatile()
|
||||
{
|
||||
GLint format = GL_RGBA;
|
||||
if (data->getFormat() == love::font::GlyphData::FORMAT_LUMINOSITY_ALPHA) format = GL_LUMINANCE_ALPHA;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -108,7 +110,7 @@ namespace opengl
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
@@ -124,6 +126,16 @@ namespace opengl
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
float Glyph::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float Glyph::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_GLYPH_H
|
||||
@@ -62,7 +62,10 @@ namespace opengl
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
|
||||
@@ -410,26 +410,12 @@ namespace opengl
|
||||
return new Quad(v, sw, sh);
|
||||
}
|
||||
|
||||
Font * Graphics::newFont(Data * data, int size)
|
||||
Font * Graphics::newFont(love::font::FontData * data)
|
||||
{
|
||||
Font * font = new TrueTypeFont(data, size);
|
||||
Font * font = new Font(data);
|
||||
|
||||
// Load it and check for errors.
|
||||
if(!font->load())
|
||||
{
|
||||
delete font;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
Font * Graphics::newImageFont(Image * image, const char * glyphs, float)
|
||||
{
|
||||
Font * font = new ImageFont(image, std::string(glyphs));
|
||||
|
||||
// Load it and check for errors.
|
||||
if(!font->load())
|
||||
if(!font)
|
||||
{
|
||||
delete font;
|
||||
return 0;
|
||||
@@ -497,15 +483,6 @@ namespace opengl
|
||||
currentFont->retain();
|
||||
}
|
||||
|
||||
void Graphics::setFont( Data * data, int size )
|
||||
{
|
||||
if(currentFont != 0)
|
||||
currentFont->release();
|
||||
|
||||
currentFont = new TrueTypeFont(data, size);
|
||||
currentFont->load();
|
||||
}
|
||||
|
||||
Font * Graphics::getFont()
|
||||
{
|
||||
return currentFont;
|
||||
|
||||
@@ -33,12 +33,13 @@
|
||||
// LOVE
|
||||
#include <graphics/Graphics.h>
|
||||
|
||||
#include <font/FontData.h>
|
||||
|
||||
#include <image/Image.h>
|
||||
#include <image/ImageData.h>
|
||||
|
||||
#include "Font.h"
|
||||
#include "Image.h"
|
||||
#include "TrueTypeFont.h"
|
||||
#include "ImageFont.h"
|
||||
#include "Quad.h"
|
||||
#include "SpriteBatch.h"
|
||||
#include "ParticleSystem.h"
|
||||
@@ -248,12 +249,7 @@ namespace opengl
|
||||
/**
|
||||
* Creates a Font object.
|
||||
**/
|
||||
Font * newFont(Data * data, int size);
|
||||
|
||||
/**
|
||||
* Creates an ImageFont object.
|
||||
**/
|
||||
Font * newImageFont(Image * image, const char * glyphs, float spacing = 1);
|
||||
Font * newFont(love::font::FontData * data);
|
||||
|
||||
SpriteBatch * newSpriteBatch(Image * image, int size, int usage);
|
||||
|
||||
@@ -285,16 +281,6 @@ namespace opengl
|
||||
* @parm font A Font object.
|
||||
**/
|
||||
void setFont(Font * font);
|
||||
|
||||
/**
|
||||
* Sets a default font. The font is
|
||||
* loaded and sent to the GPU every time this is called,
|
||||
* so no over-using.
|
||||
* @param data Data
|
||||
* @param size The size of the font.
|
||||
**/
|
||||
void setFont(Data * data, int size = 12);
|
||||
|
||||
/**
|
||||
* Gets the current Font, or nil if none.
|
||||
**/
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace opengl
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f);
|
||||
glRotatef(LOVE_TORAD(angle), 0, 0, 1.0f);
|
||||
glRotatef(LOVE_TODEG(angle), 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
|
||||
GLuint TrueTypeFont = list;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "wrap_Graphics.h"
|
||||
|
||||
#include <image/ImageData.h>
|
||||
#include <font/Rasterizer.h>
|
||||
#include <font/FontData.h>
|
||||
|
||||
#include <scripts/graphics.lua.h>
|
||||
|
||||
@@ -197,69 +199,69 @@ namespace opengl
|
||||
|
||||
int w_newFont1(lua_State * L)
|
||||
{
|
||||
Data * d = 0;
|
||||
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_convobj(L, 1, "filesystem", "newFile");
|
||||
|
||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
{
|
||||
// Check the value.
|
||||
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
try {
|
||||
d = file->read();
|
||||
} catch (Exception & e) {
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
// Convert to Data, if necessary.
|
||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T)) {
|
||||
love::filesystem::File * f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
Data * d = f->read();
|
||||
lua_pop(L, 1); // get rid of the file
|
||||
luax_newtype(L, "Data", DATA_T, (void*)d);
|
||||
}
|
||||
else if(luax_istype(L, 1, DATA_T))
|
||||
{
|
||||
d = luax_checktype<Data>(L, 1, "Data", DATA_T);
|
||||
} else { // This is not the type you're looking for.
|
||||
return luaL_error(L, "love.graphics.newFont() requires a string, File, or font data as argument #1");
|
||||
|
||||
// Convert to Rasterizer, if necessary.
|
||||
if(luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, FONT_FONT_DATA_T)) {
|
||||
int idxs[] = {1, 2};
|
||||
luax_convobj(L, idxs, 2, "font", "newRasterizer");
|
||||
}
|
||||
|
||||
// Second optional parameter can be a number:
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
Font * font;
|
||||
try {
|
||||
font = instance->newFont(d, size);
|
||||
} catch (Exception & e) {
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
|
||||
// Convert to FontData, if necessary.
|
||||
if(luax_istype(L, 1, FONT_RASTERIZER_T))
|
||||
luax_convobj(L, 1, "font", "newFontData");
|
||||
|
||||
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
|
||||
|
||||
// Create the font.
|
||||
Font * font = instance->newFont(data);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load the font");
|
||||
|
||||
return luaL_error(L, "Could not load font.");
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Font", GRAPHICS_FONT_T, (void*)font);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newImageFont(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_convobj(L, 1, "filesystem", "newFile");
|
||||
|
||||
// Convert to Image, if necessary.
|
||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
luax_convobj(L, 1, "graphics", "newImage");
|
||||
|
||||
// Check the value.
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
|
||||
|
||||
const char * glyphs = luaL_checkstring(L, 2);
|
||||
|
||||
Font * font = instance->newImageFont(image, glyphs);
|
||||
|
||||
// Convert to ImageData if necessary.
|
||||
if(lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, DATA_T))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
|
||||
// Convert to Rasterizer if necessary.
|
||||
if(luax_istype(L, 1, IMAGE_IMAGE_DATA_T)) {
|
||||
int idxs[] = {1, 2};
|
||||
luax_convobj(L, idxs, 2, "font", "newRasterizer");
|
||||
}
|
||||
|
||||
// Convert to FontData, if necessary.
|
||||
if(luax_istype(L, 1, FONT_RASTERIZER_T))
|
||||
luax_convobj(L, 1, "font", "newFontData");
|
||||
|
||||
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
|
||||
|
||||
// Create the font.
|
||||
Font * font = instance->newFont(data);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load the font");
|
||||
|
||||
return luaL_error(L, "Could not load font.");
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Font", GRAPHICS_FONT_T, (void*)font);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -329,25 +331,43 @@ namespace opengl
|
||||
// The second parameter is an optional int.
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
// If the first parameter is a string, convert it to a file.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_convobj(L, 1, "filesystem", "newFile");
|
||||
|
||||
// If the first parameter is a File, use another setFont function.
|
||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
{
|
||||
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
instance->setFont(file->read(), size);
|
||||
return 0;
|
||||
Font * font;
|
||||
|
||||
// If the first parameter isn't a Font, create a new one
|
||||
if (!luax_istype(L, 1, GRAPHICS_FONT_T)) {
|
||||
lua_pushinteger(L, size); // push the size
|
||||
lua_insert(L, 2); // move it to its proper place
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_convobj(L, 1, "filesystem", "newFile");
|
||||
|
||||
// Convert to Data, if necessary.
|
||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T)) {
|
||||
love::filesystem::File * f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
Data * d = f->read();
|
||||
lua_pop(L, 1); // get rid of the file
|
||||
luax_newtype(L, "Data", DATA_T, (void*)d);
|
||||
}
|
||||
|
||||
// Convert to Rasterizer, if necessary.
|
||||
if(luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, FONT_FONT_DATA_T)) {
|
||||
int idxs[] = {1, 2};
|
||||
luax_convobj(L, idxs, 2, "font", "newRasterizer");
|
||||
}
|
||||
|
||||
// Convert to FontData, if necessary.
|
||||
if(luax_istype(L, 1, FONT_RASTERIZER_T))
|
||||
luax_convobj(L, 1, "font", "newFontData");
|
||||
|
||||
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
|
||||
|
||||
// Create the font.
|
||||
font = instance->newFont(data);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load font.");
|
||||
}
|
||||
else if(luax_istype(L, 1, DATA_T))
|
||||
{
|
||||
Data * data = luax_checktype<Data>(L, 1, "Data", DATA_T);
|
||||
instance->setFont(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Font * font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
|
||||
else font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
|
||||
instance->setFont(font);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user