Fresco/Berlin/modules/Fonts Font.cc,1.5,1.6 Font.hh,1.3,1.4 FontKitImpl.cc,1.8,1.9 FontKitImpl.hh,1.7,1.8 Glyph.cc,1.6,1.7 Glyph.hh,1.5,1.6

Nick Lewycky <[email protected]>
Newsgroups gmane.comp.video.fresco.cvs
Message-ID <[email protected]>
Update of /cvs/fresco/Fresco/Berlin/modules/Fonts
In directory purcel:/tmp/cvs-serv6529/Berlin/modules/Fonts

Modified Files:
	Font.cc Font.hh FontKitImpl.cc FontKitImpl.hh Glyph.cc 
	Glyph.hh 
Log Message:
Make it compile again after Tobias' scene graph debugging patch.
Preliminary (untested) implementation of decompose.
Size now means point size, an unsigned long.



Index: Font.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Fonts/Font.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Font.cc	17 Feb 2003 02:10:33 -0000	1.5
+++ Font.cc	2 Mar 2003 15:13:01 -0000	1.6
@@ -27,7 +27,7 @@
 namespace FontKit
 {
 
-Font::Font(const char *filename, int size, FT_Library library)
+Font::Font(const char *filename, CORBA::ULong size, FT_Library library)
   : my_ftlib(library), my_size(size)
 {
   if (FT_New_Face(my_ftlib, filename, 0, &my_face) != 0)
@@ -45,7 +45,7 @@
 
 CORBA::Boolean Font::has_char(Fresco::Unichar c)
 {
-  return FT_Get_Char_Index(my_face, c);
+  return FT_Get_Char_Index(my_face, c) != 0;
 }
 
 CORBA::Boolean Font::can_display(Fresco::Unichar begin, Fresco::Unichar end)
@@ -90,12 +90,17 @@
 Fresco::Vertex Font::kerning(Fresco::Unichar first, Fresco::Unichar second)
 {
   // XXX this is BIDI-incorrect, of course...
-  FT_Vector kern;
-  FT_Get_Kerning(my_face, first, second, FT_KERNING_DEFAULT, &kern);
-  Fresco::Vertex v;
-  v.x = kern.x / 0x10000;
-  v.y = kern.y / 0x10000;
-  return v;
+  Fresco::Vertex k;
+  k.x = 0; k.y = 0;
+  if (FT_HAS_KERNING(my_face))
+    {
+      FT_Vector kern;
+      FT_Get_Kerning(my_face, FT_Get_Char_Index(my_face, first),
+          FT_Get_Char_Index(my_face, second), FT_KERNING_UNFITTED, &kern);
+      k.x = kern.x >> 6;
+      k.y = kern.y >> 6;
+    }
+  return k;
 }
 
 CORBA::Float Font::angle()

Index: Font.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Fonts/Font.hh,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Font.hh	17 Feb 2003 02:10:33 -0000	1.3
+++ Font.hh	2 Mar 2003 15:13:01 -0000	1.4
@@ -43,7 +43,7 @@
              public virtual IdentifiableImpl
 {
 public:
-  Font(const char *filename, int size, FT_Library library);
+  Font(const char *filename, CORBA::ULong size, FT_Library library);
   virtual ~Font();
 
   virtual Fresco::Glyph_ptr glyph_char(Fresco::Unichar c);
@@ -62,7 +62,7 @@
 private:
   FT_Library my_ftlib;
   FT_Face my_face;
-  Fresco::Coord my_size;
+  CORBA::ULong my_size;
 };
 
 } // namespace

Index: FontKitImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Fonts/FontKitImpl.cc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- FontKitImpl.cc	20 Feb 2003 02:38:20 -0000	1.8
+++ FontKitImpl.cc	2 Mar 2003 15:13:01 -0000	1.9
@@ -40,15 +40,18 @@
 class FontDecorator : public MonoGraphic
 {
 public:
-  FontDecorator(Font_ptr f) : my_font(f) {}
+  FontDecorator(Font_ptr f) : my_font(Fresco::Font::_duplicate(f)) {}
   virtual void traverse(Traversal_ptr traversal)
   {
     traversal->visit(Graphic_var(_this()));
   }
   virtual void draw(DrawTraversal_ptr traversal)
   {
-    DrawingKit_var drawing = traversal->drawing();
     // and do... NOTHING! yet.
+#if 0
+    DrawingKit_var drawing = traversal->drawing();
+    drawing->set_font(my_font);
+#endif
     MonoGraphic::traverse(traversal);
   }
   virtual void pick(PickTraversal_ptr traversal)
@@ -56,21 +59,23 @@
     MonoGraphic::traverse(traversal);
   }
 private:
-  Font_ptr my_font;
+  Font_var my_font;
 };
 
 class FontSizeDecorator : public MonoGraphic
 {
 public:
-  FontSizeDecorator(Coord s) : my_size(s) {}
+  FontSizeDecorator(CORBA::ULong s) : my_size(s) {}
   virtual void traverse(Traversal_ptr traversal)
   {
     traversal->visit(Graphic_var(_this()));
   }
   virtual void draw(DrawTraversal_ptr traversal)
   {
-    DrawingKit_var drawing = traversal->drawing();
     // and do... NOTHING! yet.
+#if 0
+    DrawingKit_var drawing = traversal->drawing();
+#endif
     MonoGraphic::traverse(traversal);
   }
   virtual void pick(PickTraversal_ptr traversal)
@@ -78,7 +83,7 @@
     MonoGraphic::traverse(traversal);
   }
 private:
-  Coord my_size;
+  CORBA::ULong my_size;
 };
 
 FontKitImpl::FontIterator::FontIterator(FontKitImpl *fk)
@@ -117,17 +122,17 @@
   for (Prague::Path::iterator i = path.begin(); i != path.end(); ++i)
     {
       Directory directory(*i, Directory::alpha);
-      for (Prague::Directory::iterator j = directory.begin(); j != directory.end(); ++j)
-	{
-	  if ((*j)->name()[0] == '.') continue;
-	  std::string file = (*j)->long_name();
-	  if (FT_New_Face(*(my_fk->get_ftlibrary()), file.c_str(), 0, &my_face))
-	    {
-	      Logger::log(Logger::text) << "file " << file << " is not a font." << std::endl;
-	      continue;
-	    }
-	  faces.push_back(file);
-	}
+      for (Directory::iterator j = directory.begin(); j != directory.end(); ++j)
+        {
+          if ((*j)->name()[0] == '.') continue;
+          std::string file = (*j)->long_name();
+          if (FT_New_Face(*(my_fk->get_ftlibrary()), file.c_str(), 0, &my_face))
+            {
+              Logger::log(Logger::text) << "file " << file << " is not a font." << std::endl;
+              continue;
+            }
+          faces.push_back(file);
+        }
     }
 }
 
@@ -153,51 +158,48 @@
   return f->_this();
 }
 
-Font_ptr FontKitImpl::filename(const char *fn, const Fresco::Unistring &style,
-                               const Fresco::Coord size)
+Font_ptr FontKitImpl::filename(const char *fn, const Unistring &style,
+                               const CORBA::ULong size)
 {
   Font *f = new Font(fn, size, my_library);
   return f->_this();
 }
 
-Font_ptr FontKitImpl::provide(const Fresco::Unistring &family,
-                              const Fresco::Unistring &style,
-                              const Fresco::Coord size)
+Font_ptr FontKitImpl::provide(const Unistring &family, const Unistring &style,
+                              const CORBA::ULong size)
 {
   return _cxx_default(); // XXX
 }
 
-// pantone 1 and 2 font matching functions belong here.
+// panose 1 and 2 font matching functions belong here.
 
-Fresco::Graphic_ptr FontKitImpl::set_font(Fresco::Graphic_ptr g, Font_ptr f)
+Graphic_ptr FontKitImpl::set_font(Graphic_ptr g, Font_ptr f)
 {
   Trace trace("FontKitImpl::set_font");
-  return create_and_set_body<Graphic>(new FontDecorator(f), g);
+  return create_and_set_body<Graphic>(new FontDecorator(f), g,
+                                              "FontKit/Font");
 }
 
-Fresco::Graphic_ptr FontKitImpl::size(Fresco::Graphic_ptr g,
-                                      const Fresco::Coord s)
+Graphic_ptr FontKitImpl::size(Graphic_ptr g, const CORBA::ULong s)
 {
   Trace trace("FontKitImpl::size");
-  return create_and_set_body<Graphic>(new FontSizeDecorator(s), g);
+  return create_and_set_body<Graphic>(new FontSizeDecorator(s), g,
+                                              "FontKit/size");
 }
 
-Fresco::Graphic_ptr FontKitImpl::style(Fresco::Graphic_ptr g,
-                                       const Fresco::Unistring &style)
+Graphic_ptr FontKitImpl::style(Graphic_ptr g, const Unistring &style)
 {
   Trace trace("FontKitImpl::style");
   return Graphic::_nil();
 }
 
-Fresco::Graphic_ptr FontKitImpl::delta_size(Fresco::Graphic_ptr g,
-                                            const Fresco::Coord ds)
+Graphic_ptr FontKitImpl::delta_size(Graphic_ptr g, const CORBA::Long ds)
 {
   Trace trace("FontKitImpl::delta_size");
   return Graphic::_nil();
 }
 
-Fresco::Graphic_ptr FontKitImpl::delta_style(Fresco::Graphic_ptr g,
-                                             const Fresco::Unistring &style)
+Graphic_ptr FontKitImpl::delta_style(Graphic_ptr g, const Unistring &style)
 {
   Trace trace("FontKitImpl::delta_style");
   return Graphic::_nil();

Index: FontKitImpl.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Fonts/FontKitImpl.hh,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- FontKitImpl.hh	18 Feb 2003 15:06:48 -0000	1.7
+++ FontKitImpl.hh	2 Mar 2003 15:13:01 -0000	1.8
@@ -78,17 +78,24 @@
                          ServerContextImpl *);
 
   virtual Fresco::Font_ptr _cxx_default();
-  virtual Fresco::Font_ptr filename(const char* file, const Fresco::Unistring& style,
-			            Fresco::Coord size);
-  virtual Fresco::Font_ptr provide(const Fresco::Unistring& family, const Fresco::Unistring& style,
-                           const Fresco::Coord size);
-  virtual Fresco::Graphic_ptr set_font(Fresco::Graphic_ptr g, const Fresco::Font_ptr f);
-  virtual Fresco::Graphic_ptr size(Fresco::Graphic_ptr g, const Fresco::Coord s);
-  virtual Fresco::Graphic_ptr style(Fresco::Graphic_ptr g, const Fresco::Unistring& s);
-  virtual Fresco::Graphic_ptr delta_size(Fresco::Graphic_ptr g, const Fresco::Coord ds);
-  virtual Fresco::Graphic_ptr delta_style(Fresco::Graphic_ptr g, const Fresco::Unistring& ds);
+  virtual Fresco::Font_ptr filename(const char* file,
+                                    const Fresco::Unistring& style,
+                                    const CORBA::ULong size);
+  virtual Fresco::Font_ptr provide(const Fresco::Unistring& family,
+                                   const Fresco::Unistring& style,
+                                   const CORBA::ULong size);
+  virtual Fresco::Graphic_ptr set_font(Fresco::Graphic_ptr g,
+                                       const Fresco::Font_ptr f);
+  virtual Fresco::Graphic_ptr size(Fresco::Graphic_ptr g,
+                                   const CORBA::ULong s);
+  virtual Fresco::Graphic_ptr style(Fresco::Graphic_ptr g,
+                                    const Fresco::Unistring& s);
+  virtual Fresco::Graphic_ptr delta_size(Fresco::Graphic_ptr g,
+                                         const CORBA::Long ds);
+  virtual Fresco::Graphic_ptr delta_style(Fresco::Graphic_ptr g,
+                                         const Fresco::Unistring& ds);
 
-  virtual FT_Library *FontKitImpl::get_ftlibrary();
+  virtual FT_Library *get_ftlibrary();
 
   virtual Fresco::FontIterator_ptr first_font();
   virtual Fresco::FontIterator_ptr last_font();

Index: Glyph.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Fonts/Glyph.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Glyph.cc	20 Feb 2003 02:38:20 -0000	1.6
+++ Glyph.cc	2 Mar 2003 15:13:01 -0000	1.7
@@ -29,8 +29,9 @@
 namespace FontKit
 {
 
-GlyphImpl::GlyphImpl(FT_Face face, Fresco::Coord size, FT_ULong char_index)
-  : my_face(face), my_size(size), my_uc(char_index)
+GlyphImpl::GlyphImpl(const FT_Face face, const CORBA::ULong size,
+                     Fresco::Unichar char_index)
+  : my_face(face), my_size(size*64), my_uc(char_index)
 {
   my_tr.xx = 0x10000;
   my_tr.xy = 0x00000;
@@ -40,9 +41,9 @@
 
 GlyphImpl::~GlyphImpl() {}
 
-Fresco::Raster_ptr GlyphImpl::bitmap(short unsigned int xdpi, short unsigned int ydpi)
+Fresco::Raster_ptr GlyphImpl::bitmap(CORBA::ULong xdpi, CORBA::ULong ydpi)
 {
-  if (FT_Set_Char_Size(my_face, 0, my_size*64, xdpi, ydpi) != 0)
+  if (FT_Set_Char_Size(my_face, 0, my_size, xdpi, ydpi) != 0)
     std::cerr << "FontKit bitmap: set char size failed." << std::endl;
   FT_Set_Transform(my_face, &my_tr, 0);
 
@@ -126,13 +127,28 @@
 
 Fresco::FontShape *GlyphImpl::decompose()
 {
-  FT_Set_Char_Size(my_face, 0, my_size*64, 0, 0);
+  FT_Set_Char_Size(my_face, 0, my_size, 0, 0);
   FT_Set_Transform(my_face, &my_tr, 0);
   if (FT_Load_Glyph(my_face, FT_Get_Char_Index(my_face, my_uc),
 		    FT_LOAD_DEFAULT) != 0)
       std::cerr << "FontKit decompose: load glyph failed." << std::endl;
   Fresco::FontShape *f = new Fresco::FontShape(); f->length(0);
   // use FT_Outline_Decompose
+
+  FT_Outline_Funcs funcs;
+  funcs.move_to = &moveto;
+  funcs.line_to = &lineto;
+  funcs.conic_to = &conicto;
+  funcs.shift = 0;
+  funcs.delta = 0;
+
+  FT_Glyph glyph;
+  FT_Get_Glyph(my_face->glyph, &glyph);
+  FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
+
+  FT_Outline_Decompose(&(oglyph->outline), &funcs, 0);
+
+  FT_Done_Glyph(glyph);
   FT_Set_Transform(my_face, 0, 0);
 
   return f;
@@ -140,12 +156,16 @@
 
 void GlyphImpl::char_info(Fresco::GlyphMetrics &gm)
 {
+  if (FT_Load_Glyph(my_face, FT_Get_Char_Index(my_face, my_uc),
+		    FT_LOAD_DEFAULT) != 0)
+      std::cerr << "FontKit char_info: load glyph failed." << std::endl;
+
   double scale = 1.;
-  // this isn't safe enough. We need to keep our own copy of the glyph.
+
   gm.size.x = static_cast<CORBA::Long>(my_face->glyph->metrics.width / scale);
   gm.size.y = static_cast<CORBA::Long>(my_face->glyph->metrics.height / scale);
   gm.hori_bearing.x = static_cast<CORBA::Long>(my_face->glyph->metrics.horiBearingX / scale);
-  gm.hori_bearing.y = static_cast<CORBA::Long>(my_face->glyph->metrics.horiBearingY /scale);
+  gm.hori_bearing.y = static_cast<CORBA::Long>(my_face->glyph->metrics.horiBearingY / scale);
   gm.hori_advance =  static_cast<CORBA::Long>(my_face->glyph->metrics.horiAdvance / scale);
   gm.vert_bearing.x = static_cast<CORBA::Long>(my_face->glyph->metrics.vertBearingX / scale);
   gm.vert_bearing.y = static_cast<CORBA::Long>(my_face->glyph->metrics.vertBearingY / scale);
@@ -156,7 +176,7 @@
   void *table = FT_Get_Sfnt_Table(my_face, ft_sfnt_hhea);
   if (table) {
     TT_HoriHeader *header = (TT_HoriHeader*)table;
-    gm.italic_correction = header->caret_Offset / 64.; // XXX MAYBE WRONG
+    gm.italic_correction = header->caret_Offset / scale; // XXX MAYBE WRONG
   }
 }
 
@@ -170,10 +190,53 @@
   tr->transform_vertex(e1);
   tr->transform_vertex(e2);
 
-  my_tr.xx = (e1.x-o.x)*0x10000;
-  my_tr.xy = (e1.y-o.y)*0x10000;
-  my_tr.yx = (e2.x-o.x)*0x10000;
-  my_tr.yy = (e2.y-o.y)*0x10000;
+  my_tr.xx = static_cast<FT_Fixed>((e1.x-o.x)*0x10000);
+  my_tr.xy = static_cast<FT_Fixed>((e1.y-o.y)*0x10000);
+  my_tr.yx = static_cast<FT_Fixed>((e2.x-o.x)*0x10000);
+  my_tr.yy = static_cast<FT_Fixed>((e2.y-o.y)*0x10000);
+}
+
+int moveto(FT_Vector *to, void*f)
+{
+  Fresco::FontShape *fs = (Fresco::FontShape*)f;
+
+  Fresco::FontShapeSegment *fss = new Fresco::FontShapeSegment;
+  fss->type = Fresco::move;
+  fss->to.x = to->x; fss->to.y = to->y;
+  return 0;
+}
+
+int lineto(FT_Vector *to, void*f)
+{
+  Fresco::FontShape *fs = (Fresco::FontShape*)f;
+
+  Fresco::FontShapeSegment *fss = new Fresco::FontShapeSegment;
+  fss->type = Fresco::line;
+  fss->to.x = to->x; fss->to.y = to->y;
+  return 0;
+}
+
+int conicto(FT_Vector *c, FT_Vector *to, void*f)
+{
+  Fresco::FontShape *fs = (Fresco::FontShape*)f;
+
+  Fresco::FontShapeSegment *fss = new Fresco::FontShapeSegment;
+  fss->type = Fresco::conic;
+  fss->to.x = to->x; fss->to.y = to->y;
+  fss->control1.x = c->x; fss->control1.y = c->y;
+  return 0;
+}
+
+int cubicto(FT_Vector *c1, FT_Vector *c2, FT_Vector *to, void*f)
+{
+  Fresco::FontShape *fs = (Fresco::FontShape*)f;
+
+  Fresco::FontShapeSegment *fss = new Fresco::FontShapeSegment;
+  fss->type = Fresco::conic;
+  fss->to.x = to->x; fss->to.y = to->y;
+  fss->control1.x = c1->x; fss->control1.y = c1->y;
+  fss->control2.x = c2->x; fss->control2.y = c2->y;
+  return 0;
 }
 
 } // namespace

Index: Glyph.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Fonts/Glyph.hh,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Glyph.hh	17 Feb 2003 02:10:33 -0000	1.5
+++ Glyph.hh	2 Mar 2003 15:13:01 -0000	1.6
@@ -33,6 +33,7 @@
 #include FT_FREETYPE_H
 #include FT_GLYPH_H
 #include FT_TRUETYPE_TABLES_H
+#include FT_OUTLINE_H
 
 class Fresco::Raster;
 
@@ -41,23 +42,28 @@
 namespace FontKit
 {
 
+  int moveto(FT_Vector *, void*);
+  int lineto(FT_Vector *, void*);
+  int conicto(FT_Vector *, FT_Vector *, void*);
+  int cubicto(FT_Vector *, FT_Vector *, FT_Vector *, void*);
+
 class GlyphImpl : public virtual POA_Fresco::Glyph,
                   public virtual RefCountBaseImpl,
                   public virtual IdentifiableImpl
 {
 public:
-  GlyphImpl(FT_Face face, Fresco::Coord size, FT_ULong char_index);
+  GlyphImpl(const FT_Face face, const CORBA::ULong size,
+            const Fresco::Unichar char_index);
   virtual ~GlyphImpl();
 
-  virtual Fresco::Raster_ptr bitmap(short unsigned int xdpi,
-                                    short unsigned int ydpi);
+  virtual Fresco::Raster_ptr bitmap(CORBA::ULong xdpi, CORBA::ULong ydpi);
   virtual Fresco::FontShape *decompose();
   virtual void char_info(Fresco::GlyphMetrics &gm);
   virtual void transformation(Fresco::Transform_ptr);
 private:
   FT_Face my_face;
   FT_Matrix my_tr;
-  Fresco::Coord my_size;
+  CORBA::ULong my_size;
   Fresco::Unichar my_uc;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.