[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Adonthell-commits] CVS: adonthell/src/gui Makefile.am,1.1.2.6,1.1.2.7 l
From: |
VENNIN Joel <address@hidden> |
Subject: |
[Adonthell-commits] CVS: adonthell/src/gui Makefile.am,1.1.2.6,1.1.2.7 label.cc,1.1.2.2,1.1.2.3 label.h,1.1.2.3,1.1.2.4 label_input.cc,1.1.2.2,1.1.2.3 object.h,1.1.2.2,1.1.2.3 ttf.cc,1.1.2.1,1.1.2.2 ttf.h,1.1.2.1,1.1.2.2 |
Date: |
Tue, 04 Mar 2003 20:09:28 -0500 |
Update of /cvsroot/adonthell/adonthell/src/gui
In directory subversions:/tmp/cvs-serv13042/gui
Modified Files:
Tag: Branch_road_to_0-4
Makefile.am label.cc label.h label_input.cc object.h ttf.cc
ttf.h
Log Message:
Hey, this is the first commit for Unicode stuff, now all GUI used for his
display unicode string (wstring).
Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/Makefile.am,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -r1.1.2.6 -r1.1.2.7
*** Makefile.am 17 Feb 2003 17:13:14 -0000 1.1.2.6
--- Makefile.am 5 Mar 2003 01:09:26 -0000 1.1.2.7
***************
*** 4,11 ****
container.cc font.cc keys.cc \
manager.cc scrollbar.cc scroll.cc select_list.cc theme.cc \
! event.cc label.cc label_input.cc\
font.h image.h label.h label_input.h\
scrollbar.h scroll.h select_list.h theme.h keys.h event.h types.h \
! manager.h object.h gui.h
CPPFLAGS = -I$(srcdir)/.. $(SDL_DEFS) $(SDL_CFLAGS) $(FT2_CFLAGS) $(PY_CFLAGS)
--- 4,11 ----
container.cc font.cc keys.cc \
manager.cc scrollbar.cc scroll.cc select_list.cc theme.cc \
! event.cc label.cc label_input.cc ttf.cc \
font.h image.h label.h label_input.h\
scrollbar.h scroll.h select_list.h theme.h keys.h event.h types.h \
! manager.h object.h gui.h ttf.h
CPPFLAGS = -I$(srcdir)/.. $(SDL_DEFS) $(SDL_CFLAGS) $(FT2_CFLAGS) $(PY_CFLAGS)
Index: label.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/label.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** label.cc 17 Feb 2003 17:13:14 -0000 1.1.2.2
--- label.cc 5 Mar 2003 01:09:26 -0000 1.1.2.3
***************
*** 12,15 ****
--- 12,16 ----
See the COPYING file for more details
*/
+ #include <iostream>
#include "label.h"
***************
*** 56,60 ****
Set the font
*/
! void label::set_font (font & font)
{
my_font_ = &font;
--- 57,61 ----
Set the font
*/
! void label::set_ttf (ttf & font)
{
my_font_ = &font;
***************
*** 66,71 ****
Set the text
*/
! void label::set_text (const std::string & text)
{
// init the vector and the cursor
init_vec_cursor ();
--- 67,74 ----
Set the text
*/
! void label::set_text (const std::wstring & text)
{
+ // std::cout << "TEXT: " << text << "\n";
+
// init the vector and the cursor
init_vec_cursor ();
***************
*** 82,90 ****
/**
Add text
*/
! void label::add_text (const std::string & text)
{
my_old_cursor_ = my_cursor_;
--- 85,111 ----
+ void label::add_utf16 (u_int16 c)
+ {
+ /*
+ my_old_cursor_ = my_cursor_;
+
+ if (my_old_cursor_.idx == my_text_.length ())
+ {
+ my_text_ += c;
+ my_cursor_.idx = my_text_.length ();
+ }
+ else my_text_.insert (my_cursor_.idx, c);
+
+ build (false);
+ */
+
+ }
+
+
/**
Add text
*/
! void label::add_text (const std::wstring & text)
{
my_old_cursor_ = my_cursor_;
***************
*** 157,160 ****
--- 178,182 ----
{
case NOTHING :
+ std::cout << "label::build\n";
build_form_nothing ();
update_cursor ();
***************
*** 239,243 ****
else if (my_text_[start_idx] == ' ')
{
! if ((*my_font_) [' '].length () + line_tmp.pos_x > length ())
{
line_tmp.idx_end = start_idx;
--- 261,265 ----
else if (my_text_[start_idx] == ' ')
{
! if ((*my_font_) [' '].my_advance + line_tmp.pos_x > length ())
{
line_tmp.idx_end = start_idx;
***************
*** 252,256 ****
} else
{
! line_tmp.pos_x += (*my_font_) [' '].length ();
start_idx++;
}
--- 274,278 ----
} else
{
! line_tmp.pos_x += (*my_font_) [' '].my_advance;
start_idx++;
}
***************
*** 292,296 ****
while (j < start_idx)
{
! if (line_tmp.pos_x + (*my_font_) [my_text_[j]].length
() > length ())
{
line_tmp.idx_end = j - 1;
--- 314,318 ----
while (j < start_idx)
{
! if (line_tmp.pos_x + (*my_font_)
[my_text_[j]].my_advance > length ())
{
line_tmp.idx_end = j - 1;
***************
*** 300,308 ****
line_tmp.idx_beg = j;
}
! line_tmp.pos_x += (*my_font_) [my_text_[j]].length
();
j++;
}
break;
! }
}
}
--- 322,331 ----
line_tmp.idx_beg = j;
}
! line_tmp.pos_x += (*my_font_)
[my_text_[j]].my_advance;
j++;
}
break;
! }
! // std::cout << "Word size: " << word_length_pix <<"\n";
}
}
***************
*** 364,368 ****
else
{
! line_tmp.pos_x += (*my_font_) [my_text_[i]].length ();
}
i++;
--- 387,391 ----
else
{
! line_tmp.pos_x += (*my_font_) [my_text_[i]].my_advance ;
}
i++;
***************
*** 417,421 ****
{
wlength++;
! wlengthpix += (*my_font_) [my_text_[index]].length ();
index++;
}
--- 440,444 ----
{
wlength++;
! wlengthpix += (*my_font_) [my_text_[index]].my_advance;
index++;
}
***************
*** 457,461 ****
u_int16 j = my_vect_[my_cursor_.line].idx_beg;
! while (j != my_cursor_.idx) my_cursor_.pos_x+= (*my_font_)
[my_text_[j++]].length ();
// find y position
--- 480,484 ----
u_int16 j = my_vect_[my_cursor_.line].idx_beg;
! while (j != my_cursor_.idx) my_cursor_.pos_x+= (*my_font_)
[my_text_[j++]].my_advance;
// find y position
***************
*** 474,477 ****
--- 497,502 ----
void label::draw_string (const bool at_cursor)
{
+ glyph_info * glyph;
+
u_int16 tmp_start_line;
u_int16 tx = 0, ty = 0;
***************
*** 499,504 ****
j++)
{
! (*my_font_) [my_text_[j]].draw (tx, ty, NULL, this);
! tx += (*my_font_) [my_text_[j]].length ();
}
ty += my_font_->height ();
--- 524,530 ----
j++)
{
! glyph = &((*my_font_) [my_text_[j]]);
! glyph->my_glyph->draw (tx, ty + glyph->my_yoffset, NULL, this);
! tx += glyph->my_advance;
}
ty += my_font_->height ();
***************
*** 514,519 ****
j++)
{
! (*my_font_) [my_text_[j]].draw (tx, ty, NULL, this);
! tx += (*my_font_) [my_text_[j]].length ();
}
ty += my_font_->height ();
--- 540,546 ----
j++)
{
! glyph = &((*my_font_) [my_text_[j]]);
! glyph->my_glyph->draw (tx, ty + glyph->my_yoffset, NULL, this);
! tx += glyph->my_advance;
}
ty += my_font_->height ();
***************
*** 545,552 ****
// draw the cursor
if (my_cursor_.idx == my_text_.length () || my_text_[my_cursor_.idx] ==
'\n')
! my_font_->cursor->draw (my_cursor_.pos_x, my_cursor_.pos_y,NULL,
this);
else
! my_font_->cursor->draw (my_cursor_.pos_x, my_cursor_.pos_y,0, 0,
! (*my_font_) [my_text_[my_cursor_.idx]].length
(),
my_font_->height (), NULL, this);
}
--- 572,579 ----
// draw the cursor
if (my_cursor_.idx == my_text_.length () || my_text_[my_cursor_.idx] ==
'\n')
! my_font_->get_cursor ().draw (my_cursor_.pos_x,
my_cursor_.pos_y,NULL, this);
else
! my_font_->get_cursor ().draw (my_cursor_.pos_x, my_cursor_.pos_y,0,
0,
! (*my_font_)
[my_text_[my_cursor_.idx]].my_advance,
my_font_->height (), NULL, this);
}
***************
*** 561,570 ****
lock ();
fillrect(my_cursor_.pos_x, my_cursor_.pos_y,
! my_font_->cursor->length () ,
! my_font_->cursor->height(),
gfx::screen::trans_col());
unlock ();
}
! else (*my_font_) [my_text_[my_cursor_.idx]].draw (my_cursor_.pos_x,
my_cursor_.pos_y, NULL, this);
}
--- 588,597 ----
lock ();
fillrect(my_cursor_.pos_x, my_cursor_.pos_y,
! my_font_->get_cursor ().length() ,
! my_font_->get_cursor ().height(),
gfx::screen::trans_col());
unlock ();
}
! else (*my_font_) [my_text_[my_cursor_.idx]].my_glyph->draw
(my_cursor_.pos_x, my_cursor_.pos_y, NULL, this);
}
***************
*** 585,590 ****
}
-
-
return true;
}
--- 612,615 ----
***************
*** 613,635 ****
! const std::string label::text_string () const
{
return my_text_;
}
!
const char * label::text_char () const
{
return my_text_.c_str ();
! }
!
!
!
!
!
!
!
!
!
!
!
!
--- 638,648 ----
! const std::wstring label::text_string () const
{
return my_text_;
}
! /*
const char * label::text_char () const
{
return my_text_.c_str ();
! }*/
Index: label.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/label.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -r1.1.2.3 -r1.1.2.4
*** label.h 17 Feb 2003 17:13:14 -0000 1.1.2.3
--- label.h 5 Mar 2003 01:09:26 -0000 1.1.2.4
***************
*** 17,25 ****
#include <vector>
#include <string>
#include "gfx/image.h"
#include "input.h"
! #include "font.h"
namespace gui {
--- 17,26 ----
#include <vector>
+ //#include <wstring>
#include <string>
#include "gfx/image.h"
#include "input.h"
! #include "ttf.h"
namespace gui {
***************
*** 43,47 ****
* @param font: a font
*/
! void set_font (font & font);
--- 44,48 ----
* @param font: a font
*/
! void set_ttf (ttf & font);
***************
*** 50,54 ****
* @param text: set the text
*/
! void set_text (const std::string & text);
--- 51,55 ----
* @param text: set the text
*/
! void set_text (const std::wstring & text);
***************
*** 56,62 ****
* Add text
*/
! void add_text (const std::string & text);
/**
Set the form of the display
NOTHING, AUTO_SIZE, AUTO_HEIGHT
--- 57,70 ----
* Add text
*/
! void add_text (const std::wstring & text);
!
/**
+ * Add UTF-16
+ */
+ void add_utf16 (u_int16 c);
+
+
+ /**
Set the form of the display
NOTHING, AUTO_SIZE, AUTO_HEIGHT
***************
*** 87,97 ****
Get the text in string
*/
! const std::string text_string () const;
/**
Get the text in char
*/
! const char * text_char () const;
!
/**
Resize the label
--- 95,105 ----
Get the text in string
*/
! const std::wstring text_string () const;
/**
Get the text in char
*/
! /* const char * text_char () const;
! */
/**
Resize the label
***************
*** 204,212 ****
// my_font
! font * my_font_;
// my text
! std::string my_text_;
// form display
--- 212,220 ----
// my_font
! ttf * my_font_;
// my text
! std::wstring my_text_;
// form display
Index: label_input.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/label_input.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** label_input.cc 17 Feb 2003 17:13:14 -0000 1.1.2.2
--- label_input.cc 5 Mar 2003 01:09:26 -0000 1.1.2.3
***************
*** 13,17 ****
*/
!
#include "label_input.h"
--- 13,17 ----
*/
! #include <iostream>
#include "label_input.h"
***************
*** 32,36 ****
bool label_input::input_update()
{
! if (!editable_) return false;
label::input_update();
--- 32,37 ----
bool label_input::input_update()
{
! //std::cout << "Youhou 1\n";
! if (!editable_) return false;
label::input_update();
***************
*** 42,47 ****
while((c=input::get_next_unicode())>0)
{
! cursor_undraw ();
! if((c == SDLK_BACKSPACE || c == SDLK_DELETE) && my_text_.size () >0
&& my_cursor_.idx > 0)
{
my_text_.erase(--my_cursor_.idx, 1);
--- 43,54 ----
while((c=input::get_next_unicode())>0)
{
! std::cout << "Key code: " << c << std::endl;
! cursor_undraw ();
!
! if (c == SDLK_SPACE) {
! add_text (L" ");
! std::cout << "Space\n";
! }
! else if((c == SDLK_BACKSPACE || c == SDLK_DELETE) && my_text_.size ()
>0 && my_cursor_.idx > 0)
{
my_text_.erase(--my_cursor_.idx, 1);
***************
*** 51,55 ****
lock ();
fillrect (my_cursor_.pos_x, my_cursor_.pos_y,
! (*my_font_) [my_text_[my_cursor_.idx]].length (),
my_font_->height (), gfx::screen::trans_col ());
unlock ();
--- 58,62 ----
lock ();
fillrect (my_cursor_.pos_x, my_cursor_.pos_y,
! (*my_font_) [my_text_[my_cursor_.idx]].my_advance,
my_font_->height (), gfx::screen::trans_col ());
unlock ();
***************
*** 57,67 ****
build (false);
}
! else if(c == SDLK_RETURN) add_text ("\n");
! else if(my_font_->in_table(c)) add_text((char*) &c);
}
return true;
}
-
-
-
-
--- 64,70 ----
build (false);
}
! else if(c == SDLK_RETURN) add_text (L"\n");
! else if(my_font_->in_table(c)) add_text((wchar_t*)&c);
}
return true;
}
Index: object.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/object.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** object.h 2 Feb 2003 23:29:12 -0000 1.1.2.2
--- object.h 5 Mar 2003 01:09:26 -0000 1.1.2.3
***************
*** 17,20 ****
--- 17,23 ----
#define GUI_OBJECT_H_
+ #include "gfx/image.h"
+ #include "gfx/screen.h"
+
#include "base.h"
#include "container.h"
***************
*** 23,27 ****
template<class T>
! class object : public win_base, public T
{
public:
--- 26,30 ----
template<class T>
! class object : public base, public T
{
public:
***************
*** 55,60 ****
void refresh();
! image * img_tmp_;
! image * img_brightness_;
bool auto_refresh_;
--- 58,63 ----
void refresh();
! gfx::image * img_tmp_;
! gfx::image * img_brightness_;
bool auto_refresh_;
***************
*** 69,77 ****
object<T>::object()
{
! img_tmp_ = new image();
img_tmp_->set_mask(true);
! img_brightness_ = new image();
set_auto_refresh(false);
--- 72,80 ----
object<T>::object()
{
! img_tmp_ = new gfx::image();
img_tmp_->set_mask(true);
! img_brightness_ = new gfx::image();
set_auto_refresh(false);
***************
*** 188,192 ****
{
img_tmp_->lock ();
! img_tmp_->fillrect(0,0,T::length(),T::height(),screen::trans_col());
img_tmp_->unlock ();
--- 191,195 ----
{
img_tmp_->lock ();
!
img_tmp_->fillrect(0,0,T::length(),T::height(),gfx::screen::trans_col());
img_tmp_->unlock ();
Index: ttf.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/ttf.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** ttf.cc 1 Feb 2003 14:45:34 -0000 1.1.2.1
--- ttf.cc 5 Mar 2003 01:09:26 -0000 1.1.2.2
***************
*** 14,21 ****
#include "gfx/image.h"
! #include "font.h"
! win_ttf::win_ttf ()
{
// by default no file, so no valid font
--- 14,26 ----
#include "gfx/image.h"
! #include "ttf.h"
+ /* Handy routines for converting from fixed point */
+ #define FT_FLOOR(X) ((X & -64) / 64)
+ #define FT_CEIL(X) (((X + 63) & -64) / 64)
! using namespace gui;
!
! ttf::ttf ()
{
// by default no file, so no valid font
***************
*** 27,34 ****
// set_default dpi
set_dpi (72);
}
! bool win_ttf::load (const std::string & filename)
{
int error;
--- 32,47 ----
// set_default dpi
set_dpi (72);
+ //
+ my_cursor = new gfx::image;
+ }
+
+
+ ttf::~ttf()
+ {
+ close ();
}
! bool ttf::load (const std::string & filename)
{
int error;
***************
*** 47,51 ****
}
! // load TTF font in face
error = FT_New_Face( my_library, my_filename.c_str () , 0, &my_face );
if ( error == FT_Err_Unknown_File_Format )
--- 60,64 ----
}
! // load TTF font in my_face
error = FT_New_Face( my_library, my_filename.c_str () , 0, &my_face );
if ( error == FT_Err_Unknown_File_Format )
***************
*** 55,58 ****
--- 68,74 ----
return false;
}
+
+ // error = FT_Select_Charmap (&my_face,
FT_Encoding.FT_ENCODING_UNICODE);
+
else if ( error )
{
***************
*** 61,65 ****
return false;
}
!
// Check if the font is no scalable
// WARNING : Implement in the futur
--- 77,81 ----
return false;
}
!
// Check if the font is no scalable
// WARNING : Implement in the futur
***************
*** 76,94 ****
! bool win_ttf::build ()
{
FT_Set_Char_Size( my_face, my_size << 6, my_size << 6, my_dpi, my_dpi);
return true;
}
! inline void win_ttf::set_dpi (int i) { my_dpi = i; }
! inline void win_ttf::set_size (int i) { my_size = i; }
! void win_ttf::close ()
{
if (!my_valid) return;
FT_Done_Face(my_face);
FT_Done_FreeType(my_library);
}
--- 92,296 ----
! bool ttf::build ()
{
+ FT_Fixed scale;
+
+ clean_cache ();
FT_Set_Char_Size( my_face, my_size << 6, my_size << 6, my_dpi, my_dpi);
+
+ /* get scalable font metrics */
+ scale = my_face->size->metrics.y_scale;
+ my_ascent = FT_CEIL(FT_MulFix(my_face->bbox.yMax, scale));
+ my_descent = FT_CEIL(FT_MulFix(my_face->bbox.yMin, scale));
+ my_height = my_ascent - my_descent + 1;
+ my_lineskip = FT_CEIL(FT_MulFix(my_face->height, scale));
+
+ my_underline_offset = FT_FLOOR(FT_MulFix(my_face->underline_position,
scale));
+ my_underline_height = FT_FLOOR(FT_MulFix(my_face->underline_thickness,
scale));
+ if ( my_underline_height < 1 ) my_underline_height = 1;
+
+ create_cursor ();
return true;
}
! inline void ttf::set_dpi (int i) { my_dpi = i; }
! inline void ttf::set_size (int i) { my_size = i; }
! void ttf::create_cursor ()
! {
! //create the cursor
! if ( my_cursor ) delete my_cursor;
!
! my_cursor = new gfx::image (my_size / 3, my_size );
!
! my_cursor->lock ();
! for (int i = 0; i < my_size; ++i)
! for (int j = 0; j < (my_size/3); ++j)
! my_cursor->put_pix (j,i, my_r, my_g, my_b);
! my_cursor->unlock ();
! }
!
! void ttf::close ()
{
if (!my_valid) return;
FT_Done_Face(my_face);
FT_Done_FreeType(my_library);
+ if (my_cursor) delete my_cursor;
+ clean_cache ();
+ }
+
+
+
+
+ void ttf::info ()
+ {
+ std::cout << "Filename : " << my_filename << std::endl;
+ std::cout << "Number face : " << my_face->num_faces << std::endl;
+ std::cout << "Num_glyphs : " << my_face->num_glyphs << std::endl;
+ std::cout << "Fixed size : " << my_face->num_fixed_sizes << std::endl;
+ std::cout << "Num char map: " << my_face->num_charmaps << std::endl;
+ }
+
+
+
+ void ttf::set_color (u_int8 r, u_int8 g, u_int8 b)
+ {
+ my_r = r;
+ my_g = g;
+ my_b = b;
+ }
+
+
+ u_int16 ttf::height ()
+ {
+ return my_size;
+ }
+
+ void ttf::clean_cache ()
+ {
+ //remove from memory all image *
+ for (std::map<u_int16, glyph_info *> ::iterator it = my_cache.begin (); it
!= my_cache.end ();
+ ++it)
+ delete it->second;
+ my_cache.clear ();
+ }
+
+
+ void ttf::copy_bitmap_to_image (u_int8 * bitmap_data, gfx::image * dest,
s_int16 dx, s_int16 dy)
+ {
+ u_int8 * pbmp = bitmap_data;
+
+ dest->lock ();
+ u_int32 pixelcol = gfx::screen::display.map_color (my_r, my_g, my_b);
+
+ for (int j = 0; j < dest->height (); j++)
+ for (int i = 0; i < dest->length () ; i++)
+ {
+ if (*pbmp > 128) dest->put_pix (dx + i, dy +j, pixelcol);
+ else dest->put_pix (dx + i, dy + j, gfx::screen::trans_col ());
+ pbmp++;
+ }
+ dest->unlock ();
+ }
+
+
+ glyph_info & ttf::operator [] (wchar_t letter)
+ {
+ // the first step is to find if the letter is in the cache.
+ // if not in the cache try to see if the letter exist
+ // if the letter exist add in the cache the new letter.
+ //We must convert the letter!
+ FT_UInt glyph_index;
+ glyph_index = FT_Get_Char_Index( my_face, letter);
+
+ // in_table (letter);
+
+ if (glyph_index == 0) return (*this)[' '];
+
+ std::map<u_int16, glyph_info *> ::iterator it = my_cache.find (glyph_index);
+
+ if ( it != my_cache.end ()) return *(it->second);
+
+ //nothing about the letter
+ //try to find the letter in the TFF font !
+
+ glyph_info * tmp = new glyph_info (*this, letter);
+ if (!tmp->is_ok()) return (*this)[' '];
+
+ my_cache[glyph_index] = tmp;
+
+ // std::cout << letter << " " << slot->bitmap_left << " " <<
slot->bitmap_top << std::endl;
+ // std::cout << my_size << " " << slot->bitmap.rows << " " <<
slot->horiBearingY << " " << slot->bitmap.rows + slot->horiBearingY <<
std::endl;
+
+ return *tmp;
+ }
+
+
+ gfx::image & ttf::get_cursor ()
+ {
+ return *my_cursor;
+ }
+
+ bool ttf::in_table (wchar_t letter)
+ {
+ FT_UInt glyph_index;
+ glyph_index = FT_Get_Char_Index( my_face, letter);
+ return (glyph_index != 0);
+ }
+
+ /*
+ void ttf::set_color (u_int32 col)
+ {
+ my_r = col & 255;
+ my_g = (col >> 8) & 255;
+ my_b = (col >> 16) & 255;
+ }*/
+
+
+ glyph_info::glyph_info (ttf & ft, wchar_t ch) : my_glyph (NULL)
+ {
+ FT_Face face = ft.my_face;
+ FT_GlyphSlot glyph;
+ FT_Glyph_Metrics* metrics;
+ FT_Outline* outline;
+
+ wchar_t index = FT_Get_Char_Index (face, ch);
+
+ if (FT_Load_Glyph( face, index, FT_LOAD_DEFAULT )) return;
+
+ glyph = face->glyph;
+ metrics = &glyph->metrics;
+ outline = &glyph->outline;
+
+ my_minx = FT_FLOOR(metrics->horiBearingX);
+ my_maxx = my_minx + FT_CEIL(metrics->width);
+ my_maxy = FT_FLOOR(metrics->horiBearingY);
+ my_miny = my_maxy - FT_CEIL(metrics->height);
+ my_yoffset = ft.my_ascent - my_maxy;
+ my_advance = FT_CEIL(metrics->horiAdvance);
+
+ if (FT_Render_Glyph( face->glyph, ft_render_mode_normal )) return;
+
+ my_glyph = new gfx::image (glyph->bitmap.width, glyph->bitmap.rows);
+ ft.copy_bitmap_to_image ( glyph->bitmap.buffer, my_glyph);
+ }
+
+
+ bool glyph_info::is_ok ()
+ {
+ return (my_glyph != NULL);
+ }
+
+ glyph_info::~glyph_info ()
+ {
+ if (my_glyph) delete my_glyph;
+ }
+
+
+ u_int16 glyph_info::height()
+ {
+ if (my_glyph) return my_glyph->height();
+ return 0;
}
Index: ttf.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/ttf.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** ttf.h 1 Feb 2003 14:45:34 -0000 1.1.2.1
--- ttf.h 5 Mar 2003 01:09:26 -0000 1.1.2.2
***************
*** 20,30 ****
*
*/
! #ifndef TTF__H_
! #define TTF__H_
#include <string>
! #include <vector>
! #include <ft2build.h>
#include FT_FREETYPE_H
#include "types.h"
--- 20,30 ----
*
*/
! #ifndef TTF_H_
! #define TTF_H_
#include <string>
! #include <map>
! #include "ft2build.h"
#include FT_FREETYPE_H
#include "types.h"
***************
*** 34,121 ****
! class win_ttf
! {
! public:
! /**
! * Default constructor
! */
! win_ttf ();
!
! /**
! * Destructor
! */
! ~win_ttf ();
!
! /**
! * Load a TTF file. But do not a build !
! */
! bool load (const std::string & filename);
!
!
! /**
! * Build the font with cur configuration (size, color, dpi)
! * After build, you can draw some text;)
! */
! bool build ();
!
! /** Set dots per inch
! * You must set to 72 or 96, Why ? see documentation on www.freetype.org
! *
! * @param dots per inch
! */
! inline void set_dpi (int);
!
!
! /** Set police size
! *
! * @param font size
! */
! inline void set_size (int size);
!
!
! /** Set color
! *
! * @param r : red color
! * @param g : green color
! * @param b : blue color
! */
! void set_color (u_int8 r, u_int8 g, u_int8 b);
!
!
!
! private:
!
! /* copy bitmap to image */
! void copy_bitmap_to_image (u_int8 * bitmap_data, gfx::image * dest, s_int16
dx, s_int16 dy);
!
! /* close the library and face */
! void close ();
!
! int UTF8_to_UNICODE(u_int16 * unicode, const char *utf8, int len);
!
! /* filename of the font */
! std::string my_filename;
!
! /* valid font, true if valid */
! bool my_valid;
!
! /* library FT */
! FT_Library my_library;
!
! /* FT_Face */
! FT_Face my_face;
!
! /* dpi, dots-per-inch */
! int my_dpi;
!
! /* size */
! u_int16 my_size;
!
! /* color variable */
! u_int8 my_r, my_g, my_b;
! };
#endif
--- 34,194 ----
! namespace gui {
! class ttf;
! class glyph_info
! {
! public:
! glyph_info (ttf & ft, wchar_t ch);
!
! ~glyph_info ();
!
! bool is_ok ();
!
! u_int16 height();
!
! int my_minx;
! int my_miny;
! int my_maxx;
! int my_maxy;
! int my_yoffset;
! int my_advance;
! gfx::image * my_glyph;
! };
!
! class ttf
! {
! public:
! /**
! * Default constructor
! */
! ttf ();
!
! /**
! * Destructor
! */
! ~ttf ();
!
!
! /**
! * Load a TTF file. But do not a build !
! */
! bool load (const std::string & filename);
!
!
! /**
! * Build the font with cur configuration (size, color, dpi)
! * After build, you can draw some text;)
! */
! bool build ();
!
! /** Set dots per inch
! * You must set to 72 or 96, Why ? see documentation on
www.freetype.org
! *
! * @param dots per inch
! */
! inline void set_dpi (int);
!
!
! /** Set police size
! *
! * @param font size
! */
! inline void set_size (int size);
!
!
! /** Set color
! *
! * @param r : red color
! * @param g : green color
! * @param b : blue color
! */
! void set_color (u_int8 r, u_int8 g, u_int8 b);
!
!
! /**
! * @return the height of the font
! */
! u_int16 height ();
!
!
! /**
! * Display some font information
! */
! void info ();
!
! /**
! * The letter must be in UTF-16 !
! * Return the gfx::image which correspond at the letter in []
! */
! glyph_info & operator[](wchar_t letter);
!
! /**
! * @return the cursor
! */
! gfx::image & get_cursor ();
!
! /**
! * @return true if the letter is in the ttf
! */
! bool in_table (wchar_t letter);
!
! /* copy bitmap to image */
! void copy_bitmap_to_image (u_int8 * bitmap_data, gfx::image * dest,
s_int16 dx = 0, s_int16 dy = 0);
!
! friend class glyph_info;
! private:
!
! /* clean cache */
! void clean_cache ();
!
!
! /* close the library and face */
! void close ();
!
! /**
! * create a cursor
! */
! void create_cursor ();
!
! /* filename of the font */
! std::string my_filename;
!
! /* valid font, true if valid */
! bool my_valid;
!
! /* library FT */
! FT_Library my_library;
!
! /* FT_Face */
! FT_Face my_face;
!
! /* dpi, dots-per-inch */
! int my_dpi;
!
! /* size */
! u_int16 my_size;
!
! u_int16 my_height;
! u_int16 my_ascent;
! u_int16 my_descent;
! u_int16 my_lineskip;
! u_int16 my_underline_offset;
! u_int16 my_underline_height;
!
! int my_style;
!
! /* color variable */
! u_int8 my_r, my_g, my_b;
!
! /* font cache */
! std::map <u_int16, glyph_info *> my_cache;
!
! /* this is the cursor */
! gfx::image * my_cursor;
! };
+ }
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Adonthell-commits] CVS: adonthell/src/gui Makefile.am,1.1.2.6,1.1.2.7 label.cc,1.1.2.2,1.1.2.3 label.h,1.1.2.3,1.1.2.4 label_input.cc,1.1.2.2,1.1.2.3 object.h,1.1.2.2,1.1.2.3 ttf.cc,1.1.2.1,1.1.2.2 ttf.h,1.1.2.1,1.1.2.2,
VENNIN Joel <address@hidden> <=
- Prev by Date:
[Adonthell-commits] CVS: adonthell/src Makefile.am,1.80.2.40,1.80.2.41 input.cc,1.5,1.5.4.1 joltest.cc,1.1.2.13,1.1.2.14
- Next by Date:
[Adonthell-commits] CVS: adonthell/src/gui gui.h,NONE,1.1.2.1
- Previous by thread:
[Adonthell-commits] CVS: adonthell/src Makefile.am,1.80.2.40,1.80.2.41 input.cc,1.5,1.5.4.1 joltest.cc,1.1.2.13,1.1.2.14
- Next by thread:
[Adonthell-commits] CVS: adonthell/src/gui gui.h,NONE,1.1.2.1
- Index(es):