mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
This commit is contained in:
parent
37ee35df07
commit
4cd71ef4fe
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
static FBlitter_8bppDebug iFBlitter_8bppDebug;
|
static FBlitter_8bppDebug iFBlitter_8bppDebug;
|
||||||
|
|
||||||
extern void* AllocSprite(size_t);
|
|
||||||
|
|
||||||
void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||||
{
|
{
|
||||||
const byte *src, *src_line;
|
const byte *src, *src_line;
|
||||||
@ -33,10 +31,10 @@ void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite)
|
Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
Sprite *dest_sprite;
|
Sprite *dest_sprite;
|
||||||
dest_sprite = (Sprite *)AllocSprite(sizeof(*dest_sprite) + sprite->height * sprite->width);
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite->height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite->width;
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
|
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||||
|
|
||||||
Sprite *Encode(SpriteLoader::Sprite *sprite);
|
Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
|
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
|
static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
|
||||||
|
|
||||||
extern void* AllocSprite(size_t);
|
|
||||||
|
|
||||||
void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||||
{
|
{
|
||||||
const byte *src, *src_next;
|
const byte *src, *src_next;
|
||||||
@ -100,7 +98,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite)
|
Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
Sprite *dest_sprite;
|
Sprite *dest_sprite;
|
||||||
byte *temp_dst;
|
byte *temp_dst;
|
||||||
@ -191,7 +189,7 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite)
|
|||||||
assert(index < memory);
|
assert(index < memory);
|
||||||
|
|
||||||
/* Allocate the exact amount of memory we need */
|
/* Allocate the exact amount of memory we need */
|
||||||
dest_sprite = (Sprite *)AllocSprite(sizeof(*dest_sprite) + index);
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + index);
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite->height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite->width;
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
|
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||||
|
|
||||||
Sprite *Encode(SpriteLoader::Sprite *sprite);
|
Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
|
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
static FBlitter_8bppSimple iFBlitter_8bppSimple;
|
static FBlitter_8bppSimple iFBlitter_8bppSimple;
|
||||||
|
|
||||||
extern void* AllocSprite(size_t);
|
|
||||||
|
|
||||||
void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||||
{
|
{
|
||||||
const byte *src, *src_line;
|
const byte *src, *src_line;
|
||||||
@ -46,10 +44,10 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite)
|
Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
Sprite *dest_sprite;
|
Sprite *dest_sprite;
|
||||||
dest_sprite = (Sprite *)AllocSprite(sizeof(*dest_sprite) + sprite->height * sprite->width);
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);;
|
||||||
|
|
||||||
dest_sprite->height = sprite->height;
|
dest_sprite->height = sprite->height;
|
||||||
dest_sprite->width = sprite->width;
|
dest_sprite->width = sprite->width;
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
|
|
||||||
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||||
|
|
||||||
Sprite *Encode(SpriteLoader::Sprite *sprite);
|
Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
|
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
int pitch; ///< The pitch of the destination buffer
|
int pitch; ///< The pitch of the destination buffer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void *AllocatorProc(size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the screen depth this blitter works for.
|
* Get the screen depth this blitter works for.
|
||||||
* This is either: 8, 16, 24 or 32.
|
* This is either: 8, 16, 24 or 32.
|
||||||
@ -49,7 +51,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Convert a sprite from the loader to our own format.
|
* Convert a sprite from the loader to our own format.
|
||||||
*/
|
*/
|
||||||
virtual Sprite *Encode(SpriteLoader::Sprite *sprite) = 0;
|
virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0;
|
||||||
|
|
||||||
virtual ~Blitter() { }
|
virtual ~Blitter() { }
|
||||||
};
|
};
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "fontcache.h"
|
#include "fontcache.h"
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
|
#include "spriteloader/spriteloader.hpp"
|
||||||
|
#include "blitter/blitter.hpp"
|
||||||
|
|
||||||
#ifdef WITH_FREETYPE
|
#ifdef WITH_FREETYPE
|
||||||
|
|
||||||
@ -361,6 +363,11 @@ static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph)
|
|||||||
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
|
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *AllocateFont(size_t size)
|
||||||
|
{
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const Sprite *GetGlyph(FontSize size, WChar key)
|
const Sprite *GetGlyph(FontSize size, WChar key)
|
||||||
{
|
{
|
||||||
@ -368,7 +375,7 @@ const Sprite *GetGlyph(FontSize size, WChar key)
|
|||||||
FT_GlyphSlot slot;
|
FT_GlyphSlot slot;
|
||||||
GlyphEntry new_glyph;
|
GlyphEntry new_glyph;
|
||||||
GlyphEntry *glyph;
|
GlyphEntry *glyph;
|
||||||
Sprite *sprite;
|
SpriteLoader::Sprite sprite;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int x;
|
int x;
|
||||||
@ -398,20 +405,20 @@ const Sprite *GetGlyph(FontSize size, WChar key)
|
|||||||
height = max(1, slot->bitmap.rows + (size == FS_NORMAL));
|
height = max(1, slot->bitmap.rows + (size == FS_NORMAL));
|
||||||
|
|
||||||
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
|
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
|
||||||
sprite = (Sprite*)calloc(width * height + 8, 1);
|
sprite.data = CallocT<SpriteLoader::CommonPixel>(width * height);
|
||||||
sprite->width = width;
|
sprite.width = width;
|
||||||
sprite->height = height;
|
sprite.height = height;
|
||||||
sprite->x_offs = slot->bitmap_left;
|
sprite.x_offs = slot->bitmap_left;
|
||||||
// XXX 2 should be determined somehow... it's right for the normal face
|
// XXX 2 should be determined somehow... it's right for the normal face
|
||||||
y_adj = (size == FS_NORMAL) ? 2 : 0;
|
y_adj = (size == FS_NORMAL) ? 2 : 0;
|
||||||
sprite->y_offs = GetCharacterHeight(size) - slot->bitmap_top - y_adj;
|
sprite.y_offs = GetCharacterHeight(size) - slot->bitmap_top - y_adj;
|
||||||
|
|
||||||
/* Draw shadow for medium size */
|
/* Draw shadow for medium size */
|
||||||
if (size == FS_NORMAL) {
|
if (size == FS_NORMAL) {
|
||||||
for (y = 0; y < slot->bitmap.rows; y++) {
|
for (y = 0; y < slot->bitmap.rows; y++) {
|
||||||
for (x = 0; x < slot->bitmap.width; x++) {
|
for (x = 0; x < slot->bitmap.width; x++) {
|
||||||
if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
|
if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
|
||||||
sprite->data[1 + x + (1 + y) * sprite->width] = SHADOW_COLOUR;
|
sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -420,17 +427,18 @@ const Sprite *GetGlyph(FontSize size, WChar key)
|
|||||||
for (y = 0; y < slot->bitmap.rows; y++) {
|
for (y = 0; y < slot->bitmap.rows; y++) {
|
||||||
for (x = 0; x < slot->bitmap.width; x++) {
|
for (x = 0; x < slot->bitmap.width; x++) {
|
||||||
if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
|
if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
|
||||||
sprite->data[x + y * sprite->width] = FACE_COLOUR;
|
sprite.data[x + y * sprite.width].m = FACE_COLOUR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_glyph.sprite = sprite;
|
new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont);
|
||||||
|
free(sprite.data);
|
||||||
new_glyph.width = (slot->advance.x >> 6) + (size != FS_NORMAL);
|
new_glyph.width = (slot->advance.x >> 6) + (size != FS_NORMAL);
|
||||||
|
|
||||||
SetGlyphPtr(size, key, &new_glyph);
|
SetGlyphPtr(size, key, &new_glyph);
|
||||||
|
|
||||||
return sprite;
|
return new_glyph.sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id)
|
|||||||
|
|
||||||
if (!sprite_loader.LoadSprite(&sprite, file_pos)) return NULL;
|
if (!sprite_loader.LoadSprite(&sprite, file_pos)) return NULL;
|
||||||
if (id == 142) sprite.height = 10; // Compensate for a TTD bug
|
if (id == 142) sprite.height = 10; // Compensate for a TTD bug
|
||||||
sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite);
|
sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
|
||||||
free(sprite.data);
|
free(sprite.data);
|
||||||
|
|
||||||
return sc->ptr;
|
return sc->ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user