Panagiotis Christopoulos Charitos 14 ani în urmă
părinte
comite
ad6fe43c32
5 a modificat fișierele cu 129 adăugiri și 8 ștergeri
  1. 1 2
      build/debug/Makefile
  2. 2 2
      build/debug/gen.cfg.py
  3. 2 2
      src/Resources/Texture/Image.cpp
  4. 111 0
      src/Ui/UiFont.cpp
  5. 13 2
      src/Ui/UiFont.h

Fișier diff suprimat deoarece este prea mare
+ 1 - 2
build/debug/Makefile


+ 2 - 2
build/debug/gen.cfg.py

@@ -3,7 +3,7 @@ sourcePaths.extend(list(walkDir("../../src")))
 
 includePaths = ["./"]
 includePaths.extend(list(sourcePaths))
-includePaths.extend(["../../extern/include", "../../extern/include/bullet", "/usr/include/python2.6"])
+includePaths.extend(["../../extern/include", "../../extern/include/bullet", "/usr/include/python2.6", "/usr/include/freetype2"])
 
 executableName = "anki"
 
@@ -11,4 +11,4 @@ compiler = "g++"
 
 compilerFlags = "-DPLATFORM_LINUX -DMATH_INTEL_SIMD -DREVISION=\\\"`svnversion ../..`\\\" -c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -pipe -g3 -fsingle-precision-constant -msse4"
 
-linkerFlags = "-rdynamic -L../../extern/lib-x86-64-linux -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lGLU -Wl,-Bdynamic -lGL -ljpeg -lSDL -lpng -lpython2.6 -lboost_system -lboost_python -lboost_filesystem -lboost_thread"
+linkerFlags = "-rdynamic -L../../extern/lib-x86-64-linux -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lGLU -Wl,-Bdynamic -lGL -ljpeg -lSDL -lpng -lpython2.6 -lboost_system -lboost_python -lboost_filesystem -lboost_thread -lfreetype"

+ 2 - 2
src/Resources/Texture/Image.cpp

@@ -28,7 +28,7 @@ void Image::loadUncompressedTga(std::fstream& fs, uint& bpp)
 	height = header6[3] * 256 + header6[2];
 	bpp = header6[4];
 
-	if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp !=32)))
+	if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp != 32)))
 	{
 		throw EXCEPTION("Invalid image information");
 	}
@@ -45,7 +45,7 @@ void Image::loadUncompressedTga(std::fstream& fs, uint& bpp)
 	}
 
 	// swap red with blue
-	for(int i=0; i<int(imageSize); i+=bytesPerPxl)
+	for(int i = 0; i < int(imageSize); i += bytesPerPxl)
 	{
 		uint temp = data[i];
 		data[i] = data[i + 2];

+ 111 - 0
src/Ui/UiFont.cpp

@@ -0,0 +1,111 @@
+#include <boost/foreach.hpp>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "UiFont.h"
+#include "Vec.h"
+#include "Texture.h"
+#include "Exception.h"
+#include "Assert.h"
+
+
+struct Glyph
+{
+	FT_Glyph glyph;
+	FT_Glyph_Metrics metrics;
+};
+
+
+inline FT_Int toPixels(FT_Int a)
+{
+	return a >> 6;
+}
+
+
+static void getGlyphs(FT_Face& face, Vec<Glyph>& glyphs)
+{
+	const uint MAX_GLYPHS = 127;
+	ASSERT(glyphs.size() == 0);
+	glyphs.resize(MAX_GLYPHS);
+
+	for(uint n = 0; n < MAX_GLYPHS; n++)
+	{
+		char c = '!' + n;
+
+		FT_UInt glyph_index = FT_Get_Char_Index(face, c);
+
+		FT_Error error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
+		if(error)
+		{
+			throw EXCEPTION("FT_Load_Glyph failed");
+		}
+
+		glyphs[n].metrics = face->glyph->metrics;
+
+		error = FT_Get_Glyph(face->glyph, &glyphs[n].glyph);
+		if(error)
+		{
+			throw EXCEPTION("FT_Get_Glyph failed");
+		}
+	}
+}
+
+
+static void copyBitmap(const unsigned char* srcImg, const FT_Vector& srcSize, const FT_Vector& pos,
+                       Vec<uchar>& destImg, const FT_Vector& destSize)
+{
+	for(int i = 0; i < srcSize.y; i++)
+	{
+		for(int j = 0; j < srcSize.x; j++)
+		{
+			int jj = j + pos.x;
+			ASSERT(jj < destSize.x);
+			int ii = i + pos.y;
+			ASSERT(ii < destSize.y);
+			destImg[ii * destSize.x + jj] = srcImg[i * srcSize.x + j];
+		}
+	}
+}
+
+
+static void computeImageSize(const Vec<Glyph>& glyphs, FT_Vector& size)
+{
+	size.x = 0;
+	size.y = 0;
+
+	BOOST_FOREACH(const Glyph& glyph, glyphs)
+	{
+		size.x += glyph.metrics.width >> 6;
+		if(size.y < glyph.metrics.height >> 6)
+		{
+			size.y = glyph.metrics.height >> 6;
+		}
+	}
+}
+
+
+static void createImage(Vec<Glyph>& glyphs, Vec<uchar>& img)
+{
+	FT_Vector imgSize;
+	computeImageSize(glyphs, imgSize);
+
+	size_t size = imgSize.x * imgSize.y * 2 * sizeof(uchar);
+	img.resize(size, 128);
+
+	FT_Vector pos = {0, 0};
+
+	BOOST_FOREACH(Glyph& glyph, glyphs)
+	{
+		FT_Glyph_To_Bitmap(&glyph.glyph, FT_RENDER_MODE_NORMAL, 0, 0);
+		FT_BitmapGlyph bit = (FT_BitmapGlyph) glyph.glyph;
+
+		FT_Vector srcSize = {toPixels(glyph.metrics.width), toPixels(glyph.metrics.height)};
+
+		copyBitmap(bit->bitmap.buffer, srcSize, pos, img, imgSize);
+
+		pos.x += toPixels(glyph.metrics.width);
+	}
+
+	//save_image(image, imgSize.x, imgSize.y);
+}

+ 13 - 2
src/Ui/UiFont.h

@@ -2,7 +2,10 @@
 #define UI_FONT_H
 
 #include <memory>
-#include "Texture.h"
+#include "StdTypes.h"
+
+
+class Texture;
 
 
 namespace Ui {
@@ -12,10 +15,18 @@ namespace Ui {
 class Font
 {
 	public:
-		Font(const char* fontFilename, uint nominalWidth, uintNominalHeight);
+		Font(const char* fontFilename, uint nominalWidth, uint NominalHeight);
 
 	private:
+		/// @todo
+		struct FtGlyph
+		{
+
+		};
+
 		std::auto_ptr<Texture> map;
+
+
 };
 
 

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff