Commit 111a39d5 authored by Nicolas.Rougier's avatar Nicolas.Rougier

Applied patch from issue #56

parent d98c61d6
......@@ -68,3 +68,5 @@ Contributors:
* Jérémie Roy (Code review, fix and new ideas)
* dsewtz (Bug report & fix)
* jcgamestoy (Bug report & fix)
* Behdad Esfahbod (Bug fix on harfbuzz demo)
* Adrian Broher (Code analysis & fix)
......@@ -31,6 +31,9 @@
* policies, either expressed or implied, of Nicolas P. Rougier.
* ============================================================================
*/
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "font-manager.h"
#include "vertex-buffer.h"
......
......@@ -31,6 +31,8 @@
* policies, either expressed or implied, of Nicolas P. Rougier.
* ============================================================================
*/
#include <math.h>
#include <stdio.h>
#include <AntTweakBar.h>
#include "freetype-gl.h"
#include "font-manager.h"
......
......@@ -31,6 +31,8 @@
* policies, either expressed or implied, of Nicolas P. Rougier.
* ============================================================================
*/
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "vertex-buffer.h"
#include "shader.h"
......
......@@ -30,6 +30,8 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "vertex-buffer.h"
#include "markup.h"
......
......@@ -30,6 +30,9 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <wchar.h>
#include <string.h>
#include <stdio.h>
#include "freetype-gl.h"
#include "vertex-buffer.h"
#include "markup.h"
......
......@@ -31,10 +31,10 @@
* policies, either expressed or implied, of Nicolas P. Rougier.
* ============================================================================
*/
#include <stdio.h>
#include "freetype-gl.h"
#include "shader.h"
#include "vertex-buffer.h"
#include <stdlib.h>
#if defined(__APPLE__)
#include <Glut/glut.h>
......
......@@ -30,6 +30,10 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "edtaa3func.h"
#include "font-manager.h"
......
......@@ -30,6 +30,8 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <stdio.h>
#include <string.h>
#include "freetype-gl.h"
#include "edtaa3func.h"
#include "font-manager.h"
......
......@@ -35,6 +35,8 @@
*
* ============================================================================
*/
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "mat4.h"
......
......@@ -35,6 +35,10 @@
*
* ============================================================================
*/
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "font-manager.h"
#include "vertex-buffer.h"
......
......@@ -30,6 +30,9 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "font-manager.h"
......
......@@ -30,6 +30,9 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "vertex-buffer.h"
#include "shader.h"
......
......@@ -35,6 +35,10 @@
*
* ============================================================================
*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <fontconfig/fontconfig.h>
#include "freetype-gl.h"
#include "font-manager.h"
#include "vertex-buffer.h"
......@@ -50,8 +54,6 @@
#else
#include <GL/glut.h>
#endif
#include <fontconfig/fontconfig.h>
// ------------------------------------------------------- global variables ---
......
......@@ -31,6 +31,9 @@
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "vertex-buffer.h"
#include "markup.h"
......
......@@ -34,6 +34,9 @@
#include <ft2build.h>
#include FT_CONFIG_OPTIONS_H
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "font-manager.h"
......
......@@ -35,6 +35,9 @@
*
* ============================================================================
*/
#include <stdio.h>
#include <wchar.h>
#include "freetype-gl.h"
#include "mat4.h"
#include "shader.h"
......
......@@ -34,15 +34,6 @@
#ifndef __FREETYPE_GL_H__
#define __FREETYPE_GL_H__
#include <math.h>
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <assert.h>
/* Mandatory */
#include "opengl.h"
#include "vec234.h"
......
......@@ -62,10 +62,10 @@ vertex_buffer_t * vbuffer;
mat4 model, view, projection;
const char *text = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
const char *font_filename = "./amiri-regular.ttf";
const hb_direction_t direction = HB_DIRECTION_RTL;
const char *language = "ar";
const hb_script_t script = HB_SCRIPT_ARABIC;
const hb_script_t script = HB_SCRIPT_ARABIC;
const char *language = "ar";
// ---------------------------------------------------------------- display ---
void display( void )
......@@ -131,7 +131,7 @@ int main( int argc, char **argv )
texture_font_t *fonts[20];
for ( i=0; i< 20; ++i )
{
fonts[i] = texture_font_new(atlas, "./amiri-regular.ttf", 12+i),
fonts[i] = texture_font_new(atlas, font_filename, 12+i),
texture_font_load_glyphs(fonts[i], text, direction, language, script );
}
......@@ -165,12 +165,12 @@ int main( int argc, char **argv )
float x = 0;
float y = 600 - i * (10+i) - 15;
float width = 0.0;
float hres = fonts[i]->hres;
for (j = 0; j < glyph_count; ++j)
{
int codepoint = glyph_info[j].codepoint;
// because of vhinting trick we need the extra 64 (hres)
float x_advance = glyph_pos[j].x_advance/(64.*64.);
float x_offset = glyph_pos[j].x_offset/(64.*64.);
float x_advance = glyph_pos[j].x_advance/(float)(hres*64);
float x_offset = glyph_pos[j].x_offset/(float)(hres*64);
texture_glyph_t *glyph = texture_font_get_glyph(fonts[i], codepoint);
if( i < (glyph_count-1) )
width += x_advance + x_offset;
......@@ -183,10 +183,10 @@ int main( int argc, char **argv )
{
int codepoint = glyph_info[j].codepoint;
// because of vhinting trick we need the extra 64 (hres)
float x_advance = glyph_pos[j].x_advance/(64.*64.);
float x_offset = glyph_pos[j].x_offset/(64.*64.);
float y_advance = glyph_pos[j].y_advance/(64.);
float y_offset = glyph_pos[j].y_offset/(64.);
float x_advance = glyph_pos[j].x_advance/(float)(hres*64);
float x_offset = glyph_pos[j].x_offset/(float)(hres*64);
float y_advance = glyph_pos[j].y_advance/(float)(64);
float y_offset = glyph_pos[j].y_offset/(float)(64);
texture_glyph_t *glyph = texture_font_get_glyph(fonts[i], codepoint);
float r = 0.0;
......@@ -194,9 +194,9 @@ int main( int argc, char **argv )
float b = 0.0;
float a = 1.0;
float x0 = x + x_offset + glyph->offset_x;
float y0 = y + y_offset + glyph->offset_y;
float x1 = x0 + glyph->width;
float y1 = y0 - glyph->height;
float y0 = floor(y + y_offset + glyph->offset_y);
float y1 = floor(y0 - glyph->height);
float s0 = glyph->s0;
float t0 = glyph->t0;
float s1 = glyph->s1;
......@@ -215,8 +215,6 @@ int main( int argc, char **argv )
hb_buffer_reset(buffer);
}
glClearColor(1,1,1,1);
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
......
......@@ -46,14 +46,9 @@ varying float v_shift;
void main()
{
vec4 current = texture2D(texture, v_texcoord);
vec4 previous= texture2D(texture, v_texcoord+vec2(-1.,0.)*pixel);
//gl_FragColor = current;
//return;
current = pow(current, vec4(1.0/v_gamma));
vec4 previous= texture2D(texture, v_texcoord+vec2(-1.,0.)*pixel);
previous= pow(previous, vec4(1.0/v_gamma));
float r = current.r;
float g = current.g;
float b = current.b;
......
......@@ -55,7 +55,7 @@ varying float v_gamma;
varying float v_shift;
void main()
{
vec2 position = vec2( floor(a_vertex.x), floor(a_vertex.y));
vec2 position = vec2( floor(a_vertex.x), a_vertex.y);
v_shift = a_vertex.x - position.x;
v_gamma = a_gamma;
v_color = a_color;
......
......@@ -107,6 +107,7 @@ texture_font_new( texture_atlas_t * atlas,
self->descender = 0;
self->filename = strdup( filename );
self->size = size;
self->hres = 100;
self->ft_face = 0;
self->hb_ft_font = 0;
......@@ -128,17 +129,16 @@ texture_font_new( texture_atlas_t * atlas,
return 0;
}
size_t hres = 64;
size_t hdpi = 72;
size_t vdpi = 72;
FT_Library_SetLcdFilter( library, FT_LCD_FILTER_LIGHT );
FT_Matrix matrix = { (int)((1.0/hres) * 0x10000L),
FT_Matrix matrix = { (int)((1.0/self->hres) * 0x10000L),
(int)((0.0) * 0x10000L),
(int)((0.0) * 0x10000L),
(int)((1.0) * 0x10000L) };
/* Get harfbuzz font structs */
FT_Set_Char_Size( self->ft_face, 0, (int)(size*64), hdpi*hres, vdpi );
/* Set char size */
FT_Set_Char_Size( self->ft_face, 0, (int)(size*64),(int)(hdpi*self->hres), vdpi );
if( error )
{
//fprintf( stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
......@@ -170,19 +170,10 @@ texture_font_new( texture_atlas_t * atlas,
}
}
}
/* Set char size */
error = FT_Set_Char_Size( self->ft_face, (int)(size*64), 0, hdpi*hres, vdpi );
if( error )
{
//fprintf( stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
// __LINE__, FT_Errors[error].code, FT_Errors[error].message );
FT_Done_Face( self->ft_face );
return 0;
}
/* Set transform matrix */
FT_Set_Transform( self->ft_face, &matrix, NULL );
/* Set harfbuzz font */
self->hb_ft_font = hb_ft_font_create( self->ft_face, NULL );
return self;
......
......@@ -147,7 +147,11 @@ typedef struct
* Font size
*/
float size;
/**
* Font hres (vertical hinting trick
*/
float hres;
/**
* Freetype face
......
......@@ -33,6 +33,9 @@
*/
#include "freetype-gl.h"
#include <stdio.h>
#include <wchar.h>
#if defined(__APPLE__)
#include <Glut/glut.h>
#elif defined(_WIN32) || defined(_WIN64)
......
......@@ -34,6 +34,8 @@
#ifndef __SHADER_H__
#define __SHADER_H__
#include "opengl.h"
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -44,6 +44,8 @@
#ifndef __TEXTURE_ATLAS_H__
#define __TEXTURE_ATLAS_H__
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -34,6 +34,8 @@
#ifndef __TEXTURE_FONT_H__
#define __TEXTURE_FONT_H__
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -34,6 +34,8 @@
#ifndef __VECTOR_H__
#define __VECTOR_H__
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment