summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2015-11-18 10:17:24 +0000
committertavmjong-free <tavmjong@free.fr>2015-11-18 10:17:24 +0000
commit1c89d667e01b9ed8a8aa283ca7332ab61857c6bc (patch)
treef6e9a0f0843f0545c5bfe61d543781133c00de96 /src/libnrtype
parentFind font metrics when font is initialized. Fill baseline table. (diff)
downloadinkscape-1c89d667e01b9ed8a8aa283ca7332ab61857c6bc.tar.gz
inkscape-1c89d667e01b9ed8a8aa283ca7332ab61857c6bc.zip
Turn FontMetrics into a class. Add maximum ascent/descent variables.
(bzr r14430.1.8)
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/Layout-TNG-Compute.cpp2
-rw-r--r--src/libnrtype/Layout-TNG-OutIter.cpp3
-rw-r--r--src/libnrtype/Layout-TNG-Output.cpp26
-rw-r--r--src/libnrtype/Layout-TNG.h44
4 files changed, 56 insertions, 19 deletions
diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp
index 6b5697b10..2081b5a6d 100644
--- a/src/libnrtype/Layout-TNG-Compute.cpp
+++ b/src/libnrtype/Layout-TNG-Compute.cpp
@@ -482,7 +482,7 @@ static void dumpUnbrokenSpans(ParagraphInfo *para){
// Vertical text, use em box center as baseline
new_line.baseline_y += 0.5 * line_height.emSize();
} else {
- new_line.baseline_y += line_height.getAscent();
+ new_line.baseline_y += line_height.getTypoAscent();
}
}
diff --git a/src/libnrtype/Layout-TNG-OutIter.cpp b/src/libnrtype/Layout-TNG-OutIter.cpp
index c7275c24e..8c29b7dbc 100644
--- a/src/libnrtype/Layout-TNG-OutIter.cpp
+++ b/src/libnrtype/Layout-TNG-OutIter.cpp
@@ -120,7 +120,8 @@ Layout::iterator Layout::getNearestCursorPositionTo(double x, double y) const
double best_y_range = DBL_MAX;
double best_x_range = DBL_MAX;
for (chunk_index = 0 ; chunk_index < _chunks.size() ; chunk_index++) {
- FontMetrics line_height = {0.0, 0.0, 0.0};
+ FontMetrics line_height;
+ line_height *= 0.0; // Set all metrics to zero.
double chunk_width = 0.0;
for ( ; span_index < _spans.size() && _spans[span_index].in_chunk == chunk_index ; span_index++) {
line_height.max(_spans[span_index].line_height);
diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp
index 0bbf266c7..9557bc84c 100644
--- a/src/libnrtype/Layout-TNG-Output.cpp
+++ b/src/libnrtype/Layout-TNG-Output.cpp
@@ -93,10 +93,24 @@ void Layout::_clearOutputObjects()
_path_fitted = NULL;
}
+void Layout::FontMetrics::set(font_instance *font)
+{
+ if( font != NULL ) {
+ ascent = font->GetTypoAscent();
+ descent = font->GetTypoDescent();
+ xheight = font->GetXHeight();
+ ascent_max = font->GetMaxAscent();
+ descent_max = font->GetMaxDescent();
+ }
+}
+
void Layout::FontMetrics::max(FontMetrics const &other)
{
- if (other.ascent > ascent) ascent = other.ascent;
- if (other.descent > descent) descent = other.descent;
+ if (other.ascent > ascent ) ascent = other.ascent;
+ if (other.descent > descent ) descent = other.descent;
+ if( other.xheight > xheight ) xheight = other.xheight;
+ if( other.ascent_max > ascent_max ) ascent_max = other.ascent_max;
+ if( other.descent_max > descent_max ) descent_max = other.descent_max;
}
void Layout::FontMetrics::computeEffective( const double &line_height_multiplier ) {
@@ -142,8 +156,8 @@ void Layout::show(DrawingGroup *in_arena, Geom::OptRect const &paintbox) const
InputStreamTextSource const *text_source = static_cast<InputStreamTextSource const *>(_input_stream[_spans[span_index].in_input_stream_item]);
text_source->style->text_decoration_data.tspan_width = _spans[span_index].width();
- text_source->style->text_decoration_data.ascender = _spans[span_index].line_height.getAscent();
- text_source->style->text_decoration_data.descender = _spans[span_index].line_height.getDescent();
+ text_source->style->text_decoration_data.ascender = _spans[span_index].line_height.getTypoAscent();
+ text_source->style->text_decoration_data.descender = _spans[span_index].line_height.getTypoDescent();
if(!span_index ||
(_chunks[_spans[span_index].in_chunk].in_line != _chunks[_spans[span_index-1].in_chunk].in_line)){
@@ -188,8 +202,8 @@ void Layout::show(DrawingGroup *in_arena, Geom::OptRect const &paintbox) const
// save the starting coordinates for the line - these are needed for figuring out dot/dash/wave phase
(void) nr_text->addComponent(_spans[span_index].font, _glyphs[glyph_index].glyph, glyph_matrix,
_glyphs[glyph_index].width,
- _spans[span_index].line_height.getAscent(),
- _spans[span_index].line_height.getDescent(),
+ _spans[span_index].line_height.getTypoAscent(),
+ _spans[span_index].line_height.getTypoDescent(),
glyph_matrix.translation()[Geom::X] - phase0
);
}
diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h
index c2895e05f..ccf4bbe43 100644
--- a/src/libnrtype/Layout-TNG.h
+++ b/src/libnrtype/Layout-TNG.h
@@ -622,20 +622,32 @@ public:
*
* It's useful for this to be public so that ScanlineMaker can use it.
*/
- struct FontMetrics {
-
- double ascent;
- double descent;
- double xheight;
+ class FontMetrics {
+ public:
+ FontMetrics() { reset(); }
+
+ void reset() {
+ ascent = 0.8;
+ descent = -0.2;
+ xheight = 0.5;
+ ascent_max = 0.8;
+ descent_max = 0.2;
+ }
+
+ inline void set( font_instance *font );
+
// CSS 2.1 dictates that font-size is based on em-size which is defined as ascent + descent
inline double emSize() const {return ascent + descent;}
// Alternatively name function for use 2.
inline double lineSize() const { return ascent + descent; }
- inline void setZero() {ascent = descent = xheight = 0.0;}
+ inline void setZero() {ascent = descent = xheight = ascent_max = descent_max = 0.0;}
// For scaling for 'font-size'.
- inline FontMetrics& operator*=(double x) {ascent *= x; descent *= x; xheight *= x; return *this;}
+ inline FontMetrics& operator*=(double x) {
+ ascent *= x; descent *= x; xheight *= x; ascent_max *= x; descent_max *= x;
+ return *this;
+ }
/// Save the larger values of ascent and descent between this and other. Needed for laying
/// out a line with mixed font-sizes, fonts, or line spacings.
@@ -644,10 +656,20 @@ public:
/// Calculate the effective ascent and descent including half "leading".
void computeEffective( const double &line_height );
- inline double getAscent() const {return ascent; }
- inline double getDescent() const {return descent; }
- inline double getXheight() const {return xheight; }
- };
+ inline double getTypoAscent() const {return ascent; }
+ inline double getTypoDescent() const {return descent; }
+ inline double getXHeight() const {return xheight; }
+ inline double getMaxAscent() const {return ascent_max; }
+ inline double getMaxDescent() const {return descent_max; }
+
+ // private:
+ double ascent; // Typographic ascent.
+ double descent; // Typographic descent.
+ double xheight; // Height of 'x' measured from alphabetic baseline.
+ double ascent_max; // Maximum ascent of all glyphs in font.
+ double descent_max; // Maximum descent of all glyphs in font.
+
+ }; // End FontMetrics
/// see _enum_converter()
struct EnumConversionItem {