mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
font_metrics split, ok from asger (And it's obvious anyway ...)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4368 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
645d93c1ec
commit
11cad84732
@ -1,3 +1,7 @@
|
||||
2002-06-11 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* font_metrics.h: move X-specific stuff out of namespace
|
||||
|
||||
2002-06-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
Fixes needed to compile with Compaq cxx 6.5.
|
||||
|
@ -1,3 +1,85 @@
|
||||
//// temporary
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file font_metrics.h
|
||||
* Copyright 1995-2002 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* \author unknown
|
||||
* \author John Levon <moz@compsoc.man.ac.uk>
|
||||
*/
|
||||
|
||||
#include "xforms/xfont_metrics.h"
|
||||
#ifndef FONT_METRICS_H
|
||||
#define FONT_METRICS_H
|
||||
|
||||
#include "LString.h"
|
||||
|
||||
class LyXFont;
|
||||
|
||||
/**
|
||||
* A namespace holding helper functions for determining
|
||||
* the screen dimensions of fonts.
|
||||
*
|
||||
* The geometry is the standard typographical geometry,
|
||||
* as follows :
|
||||
*
|
||||
* --------------+------------------<maxAscent
|
||||
* | |
|
||||
* <-------> (right bearing)
|
||||
* <-> (left bearing)
|
||||
* char ascent>___ |
|
||||
* ^ oooo | oooo
|
||||
* origin>____ | oo oo | oo oo
|
||||
* \| oo oo | oo oo
|
||||
* --------------+---ooooo--|--oooo-<baseline
|
||||
* | oo |
|
||||
* char | oo oo |
|
||||
* descent>______| oooo |
|
||||
* <- width ->
|
||||
* --------------+----------+-------<maxDescent
|
||||
*
|
||||
*/
|
||||
namespace font_metrics {
|
||||
/// return the maximum ascent of the font
|
||||
int maxAscent(LyXFont const & f);
|
||||
/// return the maximum descent of the font
|
||||
int maxDescent(LyXFont const & f);
|
||||
/// return the ascent of the char in the font
|
||||
int ascent(char c, LyXFont const & f);
|
||||
/// return the descent of the char in the font
|
||||
int descent(char c, LyXFont const & f);
|
||||
/// return the left bearing of the char in the font
|
||||
int lbearing(char c, LyXFont const & f);
|
||||
/// return the right bearing of the char in the font
|
||||
int rbearing(char c, LyXFont const & f);
|
||||
/// return the width of the string in the font
|
||||
int width(char const * s, size_t n, LyXFont const & f);
|
||||
/// return the width of the char in the font
|
||||
inline int width(char c, LyXFont const & f) {
|
||||
return width(&c, 1, f);
|
||||
}
|
||||
/// return the width of the string in the font
|
||||
inline int width(string const & s, LyXFont const & f) {
|
||||
if (s.empty()) return 0;
|
||||
return width(s.data(), s.length(), f);
|
||||
}
|
||||
/// FIXME ??
|
||||
int signedWidth(string const & s, LyXFont const & f);
|
||||
/**
|
||||
* fill in width,ascent,descent with the values for the
|
||||
* given string in the font.
|
||||
*/
|
||||
void rectText(string const & str, LyXFont const & font,
|
||||
int & width,
|
||||
int & ascent,
|
||||
int & descent);
|
||||
/**
|
||||
* fill in width,ascent,descent with the values for the
|
||||
* given string in the font for a button.
|
||||
*/
|
||||
void buttonText(string const & str, LyXFont const & font,
|
||||
int & width,
|
||||
int & ascent,
|
||||
int & descent);
|
||||
};
|
||||
|
||||
#endif // FONT_METRICS_H
|
||||
|
@ -1,3 +1,9 @@
|
||||
2002-06-11 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* xfont_metrics.h:
|
||||
* xfont_metrics.C:
|
||||
* XPainter.C: X-specific metrics stuff moved into xforms/ only
|
||||
|
||||
2002-06-11 Edwin Leuven <leuven@fee.uva.nl>
|
||||
|
||||
* FormParagraph.[Ch]: moved to mvc
|
||||
|
@ -220,7 +220,7 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
|
||||
|
||||
GC gc = lyxColorHandler->getGCForeground(f.realColor());
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
font_metrics::XSetFont(display(), gc, f);
|
||||
xfont_metrics::XSetFont(display(), gc, f);
|
||||
XDrawString(display(), owner.getPixmap(), gc, x, y, s, ls);
|
||||
} else {
|
||||
LyXFont smallfont(f);
|
||||
@ -229,15 +229,15 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
|
||||
for (size_t i = 0; i < ls; ++i) {
|
||||
char const c = uppercase(s[i]);
|
||||
if (c != s[i]) {
|
||||
font_metrics::XSetFont(display(), gc, smallfont);
|
||||
xfont_metrics::XSetFont(display(), gc, smallfont);
|
||||
XDrawString(display(), owner.getPixmap(), gc,
|
||||
tmpx, y, &c, 1);
|
||||
tmpx += font_metrics::XTextWidth(smallfont, &c, 1);
|
||||
tmpx += xfont_metrics::XTextWidth(smallfont, &c, 1);
|
||||
} else {
|
||||
font_metrics::XSetFont(display(), gc, f);
|
||||
xfont_metrics::XSetFont(display(), gc, f);
|
||||
XDrawString(display(), owner.getPixmap(), gc,
|
||||
tmpx, y, &c, 1);
|
||||
tmpx += font_metrics::XTextWidth(f, &c, 1);
|
||||
tmpx += xfont_metrics::XTextWidth(f, &c, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,7 +255,7 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
|
||||
{
|
||||
GC gc = lyxColorHandler->getGCForeground(f.realColor());
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
font_metrics::XSetFont(display(), gc, f);
|
||||
xfont_metrics::XSetFont(display(), gc, f);
|
||||
XDrawString16(display(), owner.getPixmap(), gc, x, y, s, ls);
|
||||
} else {
|
||||
LyXFont smallfont(f);
|
||||
@ -270,21 +270,21 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
|
||||
c.byte2 = uppercase(s[i].byte2);
|
||||
}
|
||||
if (c.byte2 != s[i].byte2) {
|
||||
font_metrics::XSetFont(display(), gc, smallfont);
|
||||
xfont_metrics::XSetFont(display(), gc, smallfont);
|
||||
XDrawString16(display(), owner.getPixmap(), gc,
|
||||
tmpx, y, &c, 1);
|
||||
tmpx += font_metrics::XTextWidth16(smallfont, &c, 1);
|
||||
tmpx += xfont_metrics::XTextWidth16(smallfont, &c, 1);
|
||||
} else {
|
||||
font_metrics::XSetFont(display(), gc, f);
|
||||
xfont_metrics::XSetFont(display(), gc, f);
|
||||
XDrawString16(display(), owner.getPixmap(), gc,
|
||||
tmpx, y, &c, 1);
|
||||
tmpx += font_metrics::XTextWidth16(f, &c, 1);
|
||||
tmpx += xfont_metrics::XTextWidth16(f, &c, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (f.underbar() == LyXFont::ON) {
|
||||
underline(f, x, y, font_metrics::width(s, ls, f));
|
||||
underline(f, x, y, xfont_metrics::width(s, ls, f));
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
@ -1,17 +1,17 @@
|
||||
/* This file is part of
|
||||
* ======================================================
|
||||
/**
|
||||
* \file xfont_metrics.C
|
||||
* Copyright 1995-2002 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 1995 Matthias Ettrich
|
||||
* Copyright 1995-2001 The LyX Team.
|
||||
*
|
||||
* ====================================================== */
|
||||
* \author unknown
|
||||
* \author John Levon <moz@compsoc.man.ac.uk>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma implementation "frontends/font_metrics.h"
|
||||
#pragma implementation "frontends/xfont_metrics.h"
|
||||
#endif
|
||||
|
||||
#include "support/lstrings.h"
|
||||
@ -28,8 +28,9 @@ namespace {
|
||||
inline
|
||||
XFontStruct * getXFontstruct(LyXFont const & f)
|
||||
{
|
||||
return fontloader.load(f.family(), f.series(),
|
||||
f.realShape(), f.size());
|
||||
return fontloader.load
|
||||
(f.family(), f.series(),
|
||||
f.realShape(), f.size());
|
||||
}
|
||||
|
||||
|
||||
@ -41,84 +42,74 @@ XID getFontID(LyXFont const & f)
|
||||
|
||||
} // namespace anon
|
||||
|
||||
int font_metrics::maxAscent(LyXFont const & f)
|
||||
|
||||
namespace font_metrics {
|
||||
|
||||
int maxAscent(LyXFont const & f)
|
||||
{
|
||||
return getXFontstruct(f)->ascent;
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::maxDescent(LyXFont const & f)
|
||||
int maxDescent(LyXFont const & f)
|
||||
{
|
||||
return getXFontstruct(f)->descent;
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::ascent(char c, LyXFont const & f)
|
||||
int ascent(char c, LyXFont const & f)
|
||||
{
|
||||
XFontStruct * finfo = getXFontstruct(f);
|
||||
unsigned int uc = static_cast<unsigned char>(c);
|
||||
if (finfo->per_char
|
||||
&& uc >= finfo->min_char_or_byte2
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
return finfo->per_char[uc - finfo->min_char_or_byte2].ascent;
|
||||
else
|
||||
return finfo->ascent;
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::descent(char c, LyXFont const & f)
|
||||
int descent(char c, LyXFont const & f)
|
||||
{
|
||||
XFontStruct * finfo = getXFontstruct(f);
|
||||
unsigned int uc = static_cast<unsigned char>(c);
|
||||
if (finfo->per_char
|
||||
&& uc >= finfo->min_char_or_byte2
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
return finfo->per_char[uc - finfo->min_char_or_byte2].descent;
|
||||
else
|
||||
return finfo->descent;
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::lbearing(char c, LyXFont const & f)
|
||||
int lbearing(char c, LyXFont const & f)
|
||||
{
|
||||
XFontStruct * finfo = getXFontstruct(f);
|
||||
unsigned int uc = static_cast<unsigned char>(c);
|
||||
if (finfo->per_char
|
||||
&& uc >= finfo->min_char_or_byte2
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::rbearing(char c, LyXFont const & f)
|
||||
int rbearing(char c, LyXFont const & f)
|
||||
{
|
||||
XFontStruct * finfo = getXFontstruct(f);
|
||||
unsigned int uc = static_cast<unsigned char>(c);
|
||||
if (finfo->per_char
|
||||
&& uc >= finfo->min_char_or_byte2
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
&& uc <= finfo->max_char_or_byte2+256*finfo->max_byte1)
|
||||
return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing;
|
||||
else
|
||||
return width(c, f);
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::width(char c, LyXFont const & f)
|
||||
{
|
||||
return width(&c, 1, f);
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::width(string const & s, LyXFont const & f)
|
||||
{
|
||||
if (s.empty()) return 0;
|
||||
return width(s.data(), s.length(), f);
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::width(char const * s, size_t n, LyXFont const & f)
|
||||
int width(char const * s, size_t n, LyXFont const & f)
|
||||
{
|
||||
if (!lyxrc.use_gui)
|
||||
return n;
|
||||
@ -138,8 +129,8 @@ int font_metrics::width(char const * s, size_t n, LyXFont const & f)
|
||||
Uchar c = encoding->ucs(s[i]);
|
||||
xs[i].byte1 = c >> 8;
|
||||
xs[i].byte2 = c & 0xff;
|
||||
}
|
||||
int result = width(xs.get(), n, font);
|
||||
}
|
||||
int result = xfont_metrics::width(xs.get(), n, font);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -147,7 +138,7 @@ int font_metrics::width(char const * s, size_t n, LyXFont const & f)
|
||||
return ::XTextWidth(getXFontstruct(f), s, n);
|
||||
} else {
|
||||
// emulate smallcaps since X doesn't support this
|
||||
unsigned int result = 0;
|
||||
int result = 0;
|
||||
LyXFont smallfont(f);
|
||||
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
@ -163,7 +154,7 @@ int font_metrics::width(char const * s, size_t n, LyXFont const & f)
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::signedWidth(string const & s, LyXFont const & f)
|
||||
int signedWidth(string const & s, LyXFont const & f)
|
||||
{
|
||||
if (s.empty())
|
||||
return 0;
|
||||
@ -174,17 +165,45 @@ int font_metrics::signedWidth(string const & s, LyXFont const & f)
|
||||
}
|
||||
|
||||
|
||||
//int font_metrics::width(wstring const & s, int n, LyXFont const & f)
|
||||
int font_metrics::width(XChar2b const * s, int n, LyXFont const & f)
|
||||
void rectText(string const & str, LyXFont const & font,
|
||||
int & width,
|
||||
int & ascent,
|
||||
int & descent)
|
||||
{
|
||||
static int const d = 2;
|
||||
width = font_metrics::width(str, font) + d * 2 + 2;
|
||||
ascent = font_metrics::maxAscent(font) + d;
|
||||
descent = font_metrics::maxDescent(font) + d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void buttonText(string const & str, LyXFont const & font,
|
||||
int & width,
|
||||
int & ascent,
|
||||
int & descent)
|
||||
{
|
||||
static int const d = 3;
|
||||
|
||||
width = font_metrics::width(str, font) + d * 2 + 2;
|
||||
ascent = font_metrics::maxAscent(font) + d;
|
||||
descent = font_metrics::maxDescent(font) + d;
|
||||
}
|
||||
|
||||
} // namespace font_metrics
|
||||
|
||||
namespace xfont_metrics {
|
||||
|
||||
int width(XChar2b const * s, int n, LyXFont const & f)
|
||||
{
|
||||
if (!lyxrc.use_gui)
|
||||
return n;
|
||||
|
||||
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
return ::XTextWidth16(getXFontstruct(f), s, n);
|
||||
} else {
|
||||
// emulate smallcaps since X doesn't support this
|
||||
unsigned int result = 0;
|
||||
int result = 0;
|
||||
static XChar2b c;
|
||||
LyXFont smallfont(f);
|
||||
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||
@ -204,46 +223,24 @@ int font_metrics::width(XChar2b const * s, int n, LyXFont const & f)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::XTextWidth(LyXFont const & f, char const * str, int count)
|
||||
int XTextWidth(LyXFont const & f, char const * str, int count)
|
||||
{
|
||||
return ::XTextWidth(getXFontstruct(f), str, count);
|
||||
}
|
||||
|
||||
|
||||
int font_metrics::XTextWidth16(LyXFont const & f, XChar2b const * str, int count)
|
||||
int XTextWidth16(LyXFont const & f, XChar2b const * str, int count)
|
||||
{
|
||||
return ::XTextWidth16(getXFontstruct(f), str, count);
|
||||
}
|
||||
|
||||
|
||||
void font_metrics::XSetFont(Display * display, GC gc, LyXFont const & f)
|
||||
/// hmm, not a metric !
|
||||
void XSetFont(Display * display, GC gc, LyXFont const & f)
|
||||
{
|
||||
::XSetFont(display, gc, getFontID(f));
|
||||
}
|
||||
|
||||
|
||||
void font_metrics::rectText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent)
|
||||
{
|
||||
static int const d = 2;
|
||||
width = font_metrics::width(str, font) + d * 2 + 2;
|
||||
ascent = font_metrics::maxAscent(font) + d;
|
||||
descent = font_metrics::maxDescent(font) + d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void font_metrics::buttonText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent)
|
||||
{
|
||||
static int const d = 3;
|
||||
|
||||
width = font_metrics::width(str, font) + d * 2 + 2;
|
||||
ascent = font_metrics::maxAscent(font) + d;
|
||||
descent = font_metrics::maxDescent(font) + d;
|
||||
}
|
||||
|
||||
|
||||
//} // end of namespace font
|
||||
//} // end of namespace lyx
|
||||
|
||||
} // namespace xfont_metrics
|
||||
|
@ -1,58 +1,29 @@
|
||||
// -*- C++ -*-
|
||||
/* This file is part of
|
||||
* ======================================================
|
||||
/**
|
||||
* \file xfont_metrics.h
|
||||
* Copyright 1995-2002 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 1995 Matthias Ettrich
|
||||
* Copyright 1995-2001 The LyX Team.
|
||||
*
|
||||
* ====================================================== */
|
||||
* \author unknown
|
||||
* \author John Levon <moz@compsoc.man.ac.uk>
|
||||
*/
|
||||
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
#ifndef XFONT_METRICS_H
|
||||
#define XFONT_METRICS_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "LString.h"
|
||||
|
||||
#include "font_metrics.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
class LyXFont;
|
||||
|
||||
namespace font_metrics {
|
||||
//namespace lyx {
|
||||
//namespace font {
|
||||
///
|
||||
//istruct lyxfont {
|
||||
///
|
||||
int maxAscent(LyXFont const & f);
|
||||
///
|
||||
int maxDescent(LyXFont const & f);
|
||||
///
|
||||
int ascent(char c, LyXFont const & f);
|
||||
///
|
||||
int descent(char c, LyXFont const & f);
|
||||
///
|
||||
int lbearing(char c, LyXFont const & f);
|
||||
///
|
||||
int rbearing(char c, LyXFont const & f);
|
||||
///
|
||||
int width(char const * s, size_t n, LyXFont const & f);
|
||||
///
|
||||
int width(char c, LyXFont const & f);
|
||||
///
|
||||
int width(string const & s, LyXFont const & f);
|
||||
///
|
||||
//static
|
||||
//int width(char const * s, LyXFont const & f) {
|
||||
// return width(s, strlen(s), f);
|
||||
//}
|
||||
///
|
||||
int signedWidth(string const & s, LyXFont const & f);
|
||||
///
|
||||
namespace xfont_metrics {
|
||||
int XTextWidth(LyXFont const & f, char const * str, int count);
|
||||
///
|
||||
int width(XChar2b const * s, int n, LyXFont const & f);
|
||||
@ -60,30 +31,6 @@ namespace font_metrics {
|
||||
int XTextWidth16(LyXFont const & f, XChar2b const * str, int count);
|
||||
///
|
||||
void XSetFont(Display * display, GC gc, LyXFont const & f);
|
||||
// A couple of more high-level metrics
|
||||
///
|
||||
void rectText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent);
|
||||
///
|
||||
void buttonText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent);
|
||||
//};
|
||||
}
|
||||
|
||||
//} // end of namespace font
|
||||
|
||||
// import into namespace lyx
|
||||
//using font::maxAscent;
|
||||
//using font::maxDescent;
|
||||
//using font::ascent;
|
||||
//using font::descent;
|
||||
//using font::lbearing;
|
||||
//using font::rbearing;
|
||||
//using font::width;
|
||||
//using font::signedWidth;
|
||||
//using font::XTextWidth;
|
||||
//using font::XSetFont;
|
||||
|
||||
//} // end of namespace lyx
|
||||
|
||||
#endif
|
||||
} // namespace xfont_metrics
|
||||
|
||||
#endif // FONT_METRICS_H
|
||||
|
Loading…
Reference in New Issue
Block a user