*** empty log message ***

This commit is contained in:
David Rose 2001-02-17 04:47:06 +00:00
parent 08dac49237
commit dfddc7cf2a
14 changed files with 2031 additions and 40 deletions

View File

@ -0,0 +1,18 @@
#define LOCAL_LIBS \
eggbase progbase
#define OTHER_LIBS \
pnmimagetypes:c pnmimage:c \
egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \
dtoolutil:c dconfig:c dtool:m pystub
#begin bin_target
#define TARGET egg-mkfont
#define SOURCES \
charBitmap.I charBitmap.cxx charBitmap.h \
charLayout.cxx charLayout.h \
charPlacement.I charPlacement.cxx charPlacement.h \
eggMakeFont.cxx eggMakeFont.h
#end bin_target

View File

@ -0,0 +1,36 @@
// Filename: charBitmap.I
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: CharBitmap::get_width
// Access: Public
// Description: Returns the width of the character in pixels.
////////////////////////////////////////////////////////////////////
INLINE int CharBitmap::
get_width() const {
return _block.empty() ? 0 : _block[0].size();
}
////////////////////////////////////////////////////////////////////
// Function: CharBitmap::get_height
// Access: Public
// Description: Returns the height of the character in pixels.
////////////////////////////////////////////////////////////////////
INLINE int CharBitmap::
get_height() const {
return _block.size();
}
////////////////////////////////////////////////////////////////////
// Function: SortCharBitmap::Function Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool SortCharBitmap::
operator() (const CharBitmap *c1, const CharBitmap *c2) const {
return (c1->get_height() > c2->get_height());
}

View File

@ -0,0 +1,61 @@
// Filename: charBitmap.cxx
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#include "charBitmap.h"
////////////////////////////////////////////////////////////////////
// Function: CharBitmap::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
CharBitmap::
CharBitmap(int character, int width, int height,
int hoff, int voff, double dx, double dy) {
_character = character;
_hoff = hoff;
_voff = voff;
_dx = dx;
_dy = dy;
for (int y = 0; y < height; y++) {
_block.push_back(Row(width));
}
_x = 0;
_y = 0;
}
////////////////////////////////////////////////////////////////////
// Function: CharBitmap::paint
// Access: Public
// Description: Paints a string of same-color pixels into the bitmap.
// This is called repeatedly by the rle decoder.
// Returns true when the last pixel has been painted,
// false if there is more to go.
////////////////////////////////////////////////////////////////////
bool CharBitmap::
paint(bool black, int num_pixels, int &repeat) {
if (_y < _block.size()) {
while (num_pixels > 0 && _y < _block.size()) {
assert(_x < _block[_y].size());
_block[_y][_x] = black;
_x++;
if (_x >= _block[_y].size()) {
// End of a row.
_x = 0;
_y++;
while (repeat > 0 && _y < _block.size()) {
_block[_y] = _block[_y-1];
_y++;
repeat--;
}
}
num_pixels--;
}
}
return (_y < _block.size());
}

View File

@ -0,0 +1,51 @@
// Filename: charBitmap.h
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#ifndef CHARBITMAP_H
#define CHARBITMAP_H
#include <pandatoolbase.h>
#include <vector>
////////////////////////////////////////////////////////////////////
// Class : CharBitmap
// Description : This defines a single character read from the PK
// file. It stores the kerning information as well as
// the character's decoded bitmap.
////////////////////////////////////////////////////////////////////
class CharBitmap {
public:
typedef vector<char> Row;
typedef vector<Row> Block;
CharBitmap(int character, int width, int height,
int hoff, int voff, double dx, double dy);
bool paint(bool black, int num_pixels, int &repeat);
INLINE int get_width() const;
INLINE int get_height() const;
int _character;
int _hoff, _voff;
double _dx, _dy;
Block _block;
unsigned int _x, _y;
};
// An STL function object to sort the characters in order from tallest
// to shortest. This provides a more optimal packing into the
// resulting image.
class SortCharBitmap {
public:
INLINE bool operator() (const CharBitmap *c1, const CharBitmap *c2) const;
};
#include "charBitmap.I"
#endif

View File

@ -0,0 +1,114 @@
// Filename: charLayout.cxx
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#include "charLayout.h"
#include "charBitmap.h"
#include <notify.h>
////////////////////////////////////////////////////////////////////
// Function: CharLayout::reset
// Access: Public
// Description: Removes all the characters already placed on the
// layout, and resets the parameters for a new attempt.
////////////////////////////////////////////////////////////////////
void CharLayout::
reset(int working_xsize, int working_ysize, int working_buffer_pixels) {
_working_xsize = working_xsize;
_working_ysize = working_ysize;
_working_buffer_pixels = working_buffer_pixels;
_placements.clear();
_cx = _working_buffer_pixels;
_cy = _working_buffer_pixels;
_nexty = _cy;
}
////////////////////////////////////////////////////////////////////
// Function: CharLayout::place_character
// Access: Public
// Description: Given a character bitmap and font metrics extracted
// from the pk file, find a place for it on the layout.
// Returns true if the character was placed, false if we
// ran out of room.
////////////////////////////////////////////////////////////////////
bool CharLayout::
place_character(const CharBitmap *bm) {
int width = bm->get_width() + _working_buffer_pixels;
int height = bm->get_height() + _working_buffer_pixels;
int x, y;
if (find_hole(x, y, width, height)) {
_placements.push_back(CharPlacement(bm, x, y, width, height));
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: CharLayout::find_hole
// Access: Private
// Description: Searches for a hole of at least x_size by y_size
// pixels somewhere within the layout. If a
// suitable hole is found, sets x and y to the top left
// corner and returns true; otherwise, returns false.
////////////////////////////////////////////////////////////////////
bool CharLayout::
find_hole(int &x, int &y, int x_size, int y_size) const {
y = _working_buffer_pixels;
while (y + y_size <= _working_ysize) {
int next_y = _working_ysize;
// Scan along the row at 'y'.
x = _working_buffer_pixels;
while (x + x_size <= _working_xsize) {
int next_x = x;
// Consider the spot at x, y.
const CharPlacement *overlap = find_overlap(x, y, x_size, y_size);
if (overlap == (const CharPlacement *)NULL) {
// Hooray!
return true;
}
next_x = overlap->_x + overlap->_width;
next_y = min(next_y, overlap->_y + overlap->_height);
nassertr(next_x > x, false);
x = next_x;
}
nassertr(next_y > y, false);
y = next_y;
}
// Nope, wouldn't fit anywhere.
return false;
}
////////////////////////////////////////////////////////////////////
// Function: CharLayout::find_overlap
// Access: Private
// Description: If the rectangle whose top left corner is x, y and
// whose size is x_size, y_size describes an empty hole
// that does not overlap any placed chars, returns
// NULL; otherwise, returns the first placed texture
// that the image does overlap. It is assumed the
// rectangle lies completely within the boundaries of
// the image itself.
////////////////////////////////////////////////////////////////////
const CharPlacement *CharLayout::
find_overlap(int x, int y, int x_size, int y_size) const {
Placements::const_iterator pi;
for (pi = _placements.begin(); pi != _placements.end(); ++pi) {
const CharPlacement &placement = (*pi);
if (placement.intersects(x, y, x_size, y_size)) {
return &placement;
}
}
return (const CharPlacement *)NULL;
}

View File

@ -0,0 +1,42 @@
// Filename: charLayout.h
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#ifndef CHARLAYOUT_H
#define CHARLAYOUT_H
#include <pandatoolbase.h>
#include "charPlacement.h"
#include <vector>
class CharPlacement;
////////////////////////////////////////////////////////////////////
// Class : CharLayout
// Description : This represents the arrangement of all characters on
// a working bitmap of a given size. Either all
// characters fit or they don't.
////////////////////////////////////////////////////////////////////
class CharLayout {
public:
void reset(int working_xsize, int working_ysize,
int working_buffer_pixels);
bool place_character(const CharBitmap *bm);
typedef vector<CharPlacement> Placements;
Placements _placements;
int _working_xsize, _working_ysize;
int _working_buffer_pixels;
int _cx, _cy, _nexty;
private:
bool find_hole(int &x, int &y, int x_size, int y_size) const;
const CharPlacement *find_overlap(int x, int y, int x_size, int y_size) const;
};
#endif

View File

@ -0,0 +1,21 @@
// Filename: charPlacement.I
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: CharPlacement::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE CharPlacement::
CharPlacement(const CharBitmap *bm, int x, int y,
int width, int height) :
_bm(bm),
_x(x),
_y(y),
_width(width),
_height(height)
{
}

View File

@ -0,0 +1,28 @@
// Filename: charPlacement.cxx
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#include "charPlacement.h"
#include "charBitmap.h"
////////////////////////////////////////////////////////////////////
// Function: CharPlacement::intersects
// Access: Public
// Description: Returns true if the particular position this char
// has been assigned to overlaps the rectangle whose
// top left corner is at x, y and whose size is given by
// x_size, y_size, or false otherwise.
////////////////////////////////////////////////////////////////////
bool CharPlacement::
intersects(int x, int y, int x_size, int y_size) const {
int hright = x + x_size;
int hbot = y + y_size;
int mright = _x + _width;
int mbot = _y + _height;
return !(x >= mright || hright <= _x ||
y >= mbot || hbot <= _y);
}

View File

@ -0,0 +1,35 @@
// Filename: charPlacement.h
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#ifndef CHARPLACEMENT_H
#define CHARPLACEMENT_H
#include <pandatoolbase.h>
#include "charBitmap.h"
////////////////////////////////////////////////////////////////////
// Class : CharPlacement
// Description : This specifies where a particular character will be
// placed on the working bitmap. An array of these is
// built up to lay out all the characters in the bitmap,
// and then when the layout is suitable, the bitmap is
// generated.
////////////////////////////////////////////////////////////////////
class CharPlacement {
public:
INLINE CharPlacement(const CharBitmap *bm, int x, int y,
int width, int height);
bool intersects(int x, int y, int x_size, int y_size) const;
const CharBitmap *_bm;
int _x, _y;
int _width, _height;
};
#include "charPlacement.I"
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,110 @@
// Filename: eggMakeFont.h
// Created by: drose (16Feb01)
//
////////////////////////////////////////////////////////////////////
#ifndef EGGMAKEFONT_H
#define EGGMAKEFONT_H
#include <pandatoolbase.h>
#include "charLayout.h"
#include <eggWriter.h>
#include <luse.h>
#include <pnmImage.h>
class CharPlacement;
class CharBitmap;
class EggGroup;
class EggTexture;
class EggVertexPool;
////////////////////////////////////////////////////////////////////
// Class : EggMakeFont
// Description : This program reads a rasterized font stored in a
// Metafont/TeX pk file format, and generates an egg
// file and texture map that can be used with TextNode
// to render text using the font.
////////////////////////////////////////////////////////////////////
class EggMakeFont : public EggWriter {
public:
EggMakeFont();
protected:
virtual bool handle_args(Args &args);
static bool dispatch_dimensions(const string &opt, const string &arg, void *data);
bool ns_dispatch_dimensions(const string &opt, const string &arg);
private:
TexCoordd get_uv(double x, double y);
LPoint2d get_xy(double x, double y);
void copy_character(const CharPlacement &pl);
bool consider_scale_factor(double scale_factor);
void choose_scale_factor(double too_small, double too_large);
bool choose_scale_factor();
void choose_image_size();
unsigned int fetch_nibble();
unsigned int fetch_packed_int();
unsigned int fetch_byte();
unsigned int fetch_int(int n = 4);
int fetch_signed_int(int n = 4);
bool do_character(int flag_byte);
void do_xxx(int num_bytes);
void do_yyy();
void do_post();
void do_pre();
void read_pk();
string expand_hyphen(const string &str);
public:
void run();
private:
Filename _output_image_filename;
Filename _input_pk_filename;
bool _got_output_size;
int _output_xsize, _output_ysize, _output_zsize;
double _buffer_pixels;
double _poly_pixels;
double _scale_factor;
double _gaussian_radius;
double _ppu;
bool _get_all;
string _only_chars;
double _ds;
double _vppp;
double _hppp;
bool _post;
bool _post_warning;
int _p;
bool _high;
int _dyn_f;
int _repeat_count;
vector<unsigned char> _pk;
typedef vector<CharBitmap *> Chars;
Chars _chars;
typedef map<int, PT(EggGroup)> EggDefs;
EggDefs _egg_defs;
CharLayout _layout;
int _working_xsize, _working_ysize;
int _working_buffer_pixels;
double _working_poly_pixels;
PNMImage _output_image;
EggVertexPool *_vpool;
EggGroup *_group;
EggTexture *_tref;
};
#endif

View File

@ -1,20 +1,16 @@
#define LOCAL_LIBS \
eggbase progbase
#define OTHER_LIBS \
egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \
dtoolutil:c dconfig:c dtool:m pystub
// We won't install egg-trans for now, since the one in $DWDTOOL
// is better.
#begin noinst_bin_target
#define TARGET egg-trans
#define LOCAL_LIBS \
eggbase progbase
#define OTHER_LIBS \
egg:c linmath:c putil:c express:c pandaegg:m panda:m pandaexpress:m \
dtoolutil:c dconfig:c dtool:m pystub
#define UNIX_SYS_LIBS \
m
#define SOURCES \
eggTrans.cxx eggTrans.h
#define INSTALL_HEADERS \
#end noinst_bin_target

View File

@ -80,7 +80,7 @@ ProgramBase() {
add_option("h", "", 100,
"Display this help page.",
&ProgramBase::handle_help_option);
&ProgramBase::handle_help_option, NULL, (void *)this);
// Should we report DConfig's debugging information?
if (dconfig_cat.is_debug()) {
@ -298,8 +298,7 @@ parse_command_line(int argc, char *argv[]) {
const Option &opt = *(*ii).second;
bool okflag = true;
if (opt._option_function != (OptionDispatch)NULL) {
okflag = (this->*opt._option_function)(opt._option, arg,
opt._option_data);
okflag = (*opt._option_function)(opt._option, arg, opt._option_data);
}
if (opt._bool_var != (bool *)NULL) {
(*opt._bool_var) = true;
@ -508,7 +507,7 @@ remove_option(const string &option) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_none
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// no parameters, and does nothing special. Typically
// this would be used for a boolean flag, whose presence
@ -524,7 +523,7 @@ dispatch_none(const string &, const string &, void *) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_count
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// no parameters, but whose presence on the command line
// increments an integer counter for each time it
@ -541,7 +540,7 @@ dispatch_count(const string &, const string &, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_int
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// one parameter, which is to be interpreted as an
// integer. The data pointer is to an int variable.
@ -569,7 +568,7 @@ dispatch_int(const string &opt, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_int_pair
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// a pair of integer parameters. The data pointer is to
// an array of two integers.
@ -618,7 +617,7 @@ dispatch_int_pair(const string &opt, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_double
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// one parameter, which is to be interpreted as a
// double. The data pointer is to an double variable.
@ -646,7 +645,7 @@ dispatch_double(const string &opt, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_string
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// one parameter, which is to be interpreted as a
// string. The data pointer is to a string variable.
@ -661,7 +660,7 @@ dispatch_string(const string &, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_filename
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// one parameter, which is to be interpreted as a
// filename. The data pointer is to a Filename variable.
@ -681,7 +680,7 @@ dispatch_filename(const string &opt, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_search_path
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// one parameter, which is to be interpreted as a
// colon-delimited search path. The data pointer is to
@ -704,7 +703,7 @@ dispatch_search_path(const string &opt, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::dispatch_coordinate_system
// Access: Protected
// Access: Protected, Static
// Description: Standard dispatch function for an option that takes
// one parameter, which is to be interpreted as a
// coordinate system string. The data pointer is to a
@ -727,15 +726,16 @@ dispatch_coordinate_system(const string &opt, const string &arg, void *var) {
////////////////////////////////////////////////////////////////////
// Function: ProgramBase::handle_help_option
// Access: Protected
// Access: Protected, Static
// Description: Called when the user enters '-h', this describes how
// to use the program and then exits.
////////////////////////////////////////////////////////////////////
bool ProgramBase::
handle_help_option(const string &, const string &, void *) {
show_description();
show_usage();
show_options();
handle_help_option(const string &, const string &, void *data) {
ProgramBase *me = (ProgramBase *)data;
me->show_description();
me->show_usage();
me->show_options();
exit(0);
return false;

View File

@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include <deque>
#include <map>
////////////////////////////////////////////////////////////////////
@ -36,12 +37,12 @@ public:
virtual void parse_command_line(int argc, char *argv[]);
typedef vector_string Args;
typedef deque<string> Args;
Filename _program_name;
Args _program_args;
protected:
typedef bool (ProgramBase::*OptionDispatch)(const string &opt, const string &parm, void *data);
typedef bool (*OptionDispatch)(const string &opt, const string &parm, void *data);
virtual bool handle_args(Args &args);
virtual bool post_command_line();
@ -58,17 +59,17 @@ protected:
bool redescribe_option(const string &option, const string &description);
bool remove_option(const string &option);
bool dispatch_none(const string &opt, const string &arg, void *);
bool dispatch_count(const string &opt, const string &arg, void *var);
bool dispatch_int(const string &opt, const string &arg, void *var);
bool dispatch_int_pair(const string &opt, const string &arg, void *var);
bool dispatch_double(const string &opt, const string &arg, void *var);
bool dispatch_string(const string &opt, const string &arg, void *var);
bool dispatch_filename(const string &opt, const string &arg, void *var);
bool dispatch_search_path(const string &opt, const string &arg, void *var);
bool dispatch_coordinate_system(const string &opt, const string &arg, void *var);
static bool dispatch_none(const string &opt, const string &arg, void *);
static bool dispatch_count(const string &opt, const string &arg, void *var);
static bool dispatch_int(const string &opt, const string &arg, void *var);
static bool dispatch_int_pair(const string &opt, const string &arg, void *var);
static bool dispatch_double(const string &opt, const string &arg, void *var);
static bool dispatch_string(const string &opt, const string &arg, void *var);
static bool dispatch_filename(const string &opt, const string &arg, void *var);
static bool dispatch_search_path(const string &opt, const string &arg, void *var);
static bool dispatch_coordinate_system(const string &opt, const string &arg, void *var);
bool handle_help_option(const string &opt, const string &arg, void *);
static bool handle_help_option(const string &opt, const string &arg, void *);
static void format_text(ostream &out, bool &last_newline,
const string &prefix, int indent_width,