summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/FontInstance.cpp46
-rw-r--r--src/libnrtype/Layout-TNG-Compute.cpp35
-rw-r--r--src/libnrtype/Layout-TNG-Input.cpp5
-rw-r--r--src/libnrtype/Layout-TNG.h9
4 files changed, 56 insertions, 39 deletions
diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp
index 4578efe8f..79477d431 100644
--- a/src/libnrtype/FontInstance.cpp
+++ b/src/libnrtype/FontInstance.cpp
@@ -194,7 +194,7 @@ font_instance::font_instance(void) :
_baselines[ SP_CSS_BASELINE_IDEOGRAPHIC ] = -_descent;
_baselines[ SP_CSS_BASELINE_HANGING ] = 0.8 * _ascent;
_baselines[ SP_CSS_BASELINE_MATHEMATICAL ] = 0.8 * _xheight;
- _baselines[ SP_CSS_BASELINE_CENTRAL ] = 0.5;
+ _baselines[ SP_CSS_BASELINE_CENTRAL ] = 0.5 - _descent;
_baselines[ SP_CSS_BASELINE_MIDDLE ] = 0.5 * _xheight;
_baselines[ SP_CSS_BASELINE_TEXT_BEFORE_EDGE ] = -_descent;
_baselines[ SP_CSS_BASELINE_TEXT_AFTER_EDGE ] = _ascent;
@@ -710,7 +710,7 @@ void font_instance::FindFontMetrics() {
_baselines[ SP_CSS_BASELINE_IDEOGRAPHIC ] = -_descent; // Recommendation
_baselines[ SP_CSS_BASELINE_HANGING ] = 0.8 * _ascent; // Guess
_baselines[ SP_CSS_BASELINE_MATHEMATICAL ] = 0.8 * _xheight; // Guess
- _baselines[ SP_CSS_BASELINE_CENTRAL ] = 0.5; // Definition
+ _baselines[ SP_CSS_BASELINE_CENTRAL ] = 0.5 - _descent; // Definition
_baselines[ SP_CSS_BASELINE_MIDDLE ] = 0.5 * _xheight; // Definition
_baselines[ SP_CSS_BASELINE_TEXT_BEFORE_EDGE ] = -_descent; // Definition
_baselines[ SP_CSS_BASELINE_TEXT_AFTER_EDGE ] = _ascent; // Definition
@@ -783,7 +783,7 @@ void font_instance::FindFontMetrics() {
_baselines[ SP_CSS_BASELINE_IDEOGRAPHIC ] = -_descent; // Recommendation
_baselines[ SP_CSS_BASELINE_HANGING ] = 0.8 * _ascent; // Guess
_baselines[ SP_CSS_BASELINE_MATHEMATICAL ] = 0.8 * _xheight; // Guess
- _baselines[ SP_CSS_BASELINE_CENTRAL ] = 0.5; // Definition
+ _baselines[ SP_CSS_BASELINE_CENTRAL ] = 0.5 - _descent; // Definition
_baselines[ SP_CSS_BASELINE_MIDDLE ] = 0.5 * _xheight; // Definition
_baselines[ SP_CSS_BASELINE_TEXT_BEFORE_EDGE ] = -_descent; // Definition
_baselines[ SP_CSS_BASELINE_TEXT_AFTER_EDGE ] = _ascent; // Definition
@@ -803,9 +803,9 @@ void font_instance::FindFontMetrics() {
FT_Glyph_Get_CBox( aglyph, FT_GLYPH_BBOX_UNSCALED, &acbox );
double math = (acbox.yMin + acbox.yMax)/2.0/(double)theFace->units_per_EM;
_baselines[ SP_CSS_BASELINE_MATHEMATICAL ] = math;
- std::cout << "Math baseline: - bbox: y_min: " << acbox.yMin
- << " y_max: " << acbox.yMax
- << " math: " << math << std::endl;
+ // std::cout << "Math baseline: - bbox: y_min: " << acbox.yMin
+ // << " y_max: " << acbox.yMax
+ // << " math: " << math << std::endl;
}
// Find hanging baseline... assume it is at top of 'म'.
@@ -818,26 +818,26 @@ void font_instance::FindFontMetrics() {
FT_Glyph_Get_CBox( aglyph, FT_GLYPH_BBOX_UNSCALED, &acbox );
double hanging = (double)acbox.yMax/(double)theFace->units_per_EM;
_baselines[ SP_CSS_BASELINE_HANGING ] = hanging;
- std::cout << "Hanging baseline: प: " << hanging << std::endl;
+ // std::cout << "Hanging baseline: प: " << hanging << std::endl;
}
}
#endif
- const gchar *family = pango_font_description_get_family(descr);
- std::cout << "Font: " << (family?family:"null") << std::endl;
- std::cout << " ascent: " << _ascent << std::endl;
- std::cout << " descent: " << _descent << std::endl;
- std::cout << " x-height: " << _xheight << std::endl;
- std::cout << " max ascent: " << _ascent_max << std::endl;
- std::cout << " max descent: " << _descent_max << std::endl;
- std::cout << " Baselines:" << std::endl;
- std::cout << " alphabetic: " << _baselines[ SP_CSS_BASELINE_ALPHABETIC ] << std::endl;
- std::cout << " ideographic: " << _baselines[ SP_CSS_BASELINE_IDEOGRAPHIC ] << std::endl;
- std::cout << " hanging: " << _baselines[ SP_CSS_BASELINE_HANGING ] << std::endl;
- std::cout << " math: " << _baselines[ SP_CSS_BASELINE_MATHEMATICAL ] << std::endl;
- std::cout << " central: " << _baselines[ SP_CSS_BASELINE_CENTRAL ] << std::endl;
- std::cout << " middle: " << _baselines[ SP_CSS_BASELINE_MIDDLE ] << std::endl;
- std::cout << " text_before: " << _baselines[ SP_CSS_BASELINE_TEXT_BEFORE_EDGE ] << std::endl;
- std::cout << " text_after: " << _baselines[ SP_CSS_BASELINE_TEXT_AFTER_EDGE ] << std::endl;
+ // const gchar *family = pango_font_description_get_family(descr);
+ // std::cout << "Font: " << (family?family:"null") << std::endl;
+ // std::cout << " ascent: " << _ascent << std::endl;
+ // std::cout << " descent: " << _descent << std::endl;
+ // std::cout << " x-height: " << _xheight << std::endl;
+ // std::cout << " max ascent: " << _ascent_max << std::endl;
+ // std::cout << " max descent: " << _descent_max << std::endl;
+ // std::cout << " Baselines:" << std::endl;
+ // std::cout << " alphabetic: " << _baselines[ SP_CSS_BASELINE_ALPHABETIC ] << std::endl;
+ // std::cout << " ideographic: " << _baselines[ SP_CSS_BASELINE_IDEOGRAPHIC ] << std::endl;
+ // std::cout << " hanging: " << _baselines[ SP_CSS_BASELINE_HANGING ] << std::endl;
+ // std::cout << " math: " << _baselines[ SP_CSS_BASELINE_MATHEMATICAL ] << std::endl;
+ // std::cout << " central: " << _baselines[ SP_CSS_BASELINE_CENTRAL ] << std::endl;
+ // std::cout << " middle: " << _baselines[ SP_CSS_BASELINE_MIDDLE ] << std::endl;
+ // std::cout << " text_before: " << _baselines[ SP_CSS_BASELINE_TEXT_BEFORE_EDGE ] << std::endl;
+ // std::cout << " text_after: " << _baselines[ SP_CSS_BASELINE_TEXT_AFTER_EDGE ] << std::endl;
}
}
diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp
index 05cc638f7..2ae13efa6 100644
--- a/src/libnrtype/Layout-TNG-Compute.cpp
+++ b/src/libnrtype/Layout-TNG-Compute.cpp
@@ -692,10 +692,18 @@ static void dumpUnbrokenSpans(ParagraphInfo *para){
// y-coordinate is flipped between vertical and horizontal text... delta_y is common offset but applied with opposite sign
double delta_y = unbroken_span_glyph_info->geometry.y_offset * font_size_multiplier + unbroken_span.baseline_shift;
+ SPCSSBaseline dominant_baseline = _flow._blockBaseline();
if (_block_progression == LEFT_TO_RIGHT || _block_progression == RIGHT_TO_LEFT) {
// Vertical text
+ // Default dominant baseline is determined by overall block (i.e. <text>) 'text-orientation' value.
+ if( _flow._blockTextOrientation() != SP_CSS_TEXT_ORIENTATION_SIDEWAYS ) {
+ if( dominant_baseline == SP_CSS_BASELINE_AUTO ) dominant_baseline = SP_CSS_BASELINE_CENTRAL;
+ } else {
+ if( dominant_baseline == SP_CSS_BASELINE_AUTO ) dominant_baseline = SP_CSS_BASELINE_ALPHABETIC;
+ }
+
new_glyph.y += delta_y;
// TODO: Should also check 'glyph_orientation_vertical' if 'text-orientation' is unset...
@@ -703,15 +711,10 @@ static void dumpUnbrokenSpans(ParagraphInfo *para){
(new_span.text_orientation == SP_CSS_TEXT_ORIENTATION_MIXED &&
para.pango_items[unbroken_span.pango_item_index].item->analysis.gravity == 0) ) {
- // Sideways orientation (Latin characters, CJK punctuation), 90deg rotation done at output stage.
+ // Sideways orientation (Latin characters, CJK punctuation), 90deg rotation done at output stage. zzzzzzz
new_glyph.orientation = ORIENTATION_SIDEWAYS;
- // Baseline is determined by overall block (i.e. <text>) 'text-orientation' value.
- if( _flow._blockTextOrientation() != SP_CSS_TEXT_ORIENTATION_SIDEWAYS ) {
- // Baseline is center (shift: alphabetic to center)
- new_glyph.y += 0.5 * (new_span.line_height.descent - new_span.line_height.ascent);
- }
-
+ new_glyph.y -= new_span.font_size * para.pango_items[unbroken_span.pango_item_index].font->GetBaselines()[ dominant_baseline ];
new_glyph.width = new_span.font_size * para.pango_items[unbroken_span.pango_item_index].font->Advance(unbroken_span_glyph_info->glyph, false);
} else {
@@ -719,14 +722,10 @@ static void dumpUnbrokenSpans(ParagraphInfo *para){
new_glyph.x += new_span.line_height.ascent;
- // Baseline is determined by overall block (i.e. <text>) 'text-orientation' value.
- if( _flow._blockTextOrientation() == SP_CSS_TEXT_ORIENTATION_SIDEWAYS ) {
- // Baseline is alphabetic .. sideways (shift: left edge to alphabetic)
- new_glyph.y -= new_span.line_height.descent;
- } else {
- // Baseline is center (shift: left edge to center)
- new_glyph.y -= unbroken_span_glyph_info->geometry.width * 0.5 * font_size_multiplier;
- }
+ // Glyph reference point is center (shift: left edge to center glyph)
+ new_glyph.y -= unbroken_span_glyph_info->geometry.width * 0.5 * font_size_multiplier;
+ new_glyph.y -= new_span.font_size * (para.pango_items[unbroken_span.pango_item_index].font->GetBaselines()[ dominant_baseline ] -
+ para.pango_items[unbroken_span.pango_item_index].font->GetBaselines()[ SP_CSS_BASELINE_CENTRAL ] );
new_glyph.width = new_span.font_size * para.pango_items[unbroken_span.pango_item_index].font->Advance(unbroken_span_glyph_info->glyph, true);
if( new_glyph.width == 0 ) {
@@ -736,8 +735,12 @@ static void dumpUnbrokenSpans(ParagraphInfo *para){
}
} else {
// Horizontal text
- new_glyph.y -= delta_y;
+ if( dominant_baseline == SP_CSS_BASELINE_AUTO ) dominant_baseline = SP_CSS_BASELINE_ALPHABETIC;
+
+ new_glyph.y -= delta_y;
+ new_glyph.y += new_span.font_size * para.pango_items[unbroken_span.pango_item_index].font->GetBaselines()[ dominant_baseline ];
+
new_glyph.width = unbroken_span_glyph_info->geometry.width * font_size_multiplier;
if ((new_glyph.width == 0) && (para.pango_items[unbroken_span.pango_item_index].font))
new_glyph.width = new_span.font_size * para.pango_items[unbroken_span.pango_item_index].font->Advance(unbroken_span_glyph_info->glyph, false);
diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp
index b66bbb5cd..6f5d4e5f8 100644
--- a/src/libnrtype/Layout-TNG-Input.cpp
+++ b/src/libnrtype/Layout-TNG-Input.cpp
@@ -151,6 +151,11 @@ SPCSSTextOrientation Layout::InputStreamTextSource::styleGetTextOrientation() co
return ((SPCSSTextOrientation)style->text_orientation.computed);
}
+SPCSSBaseline Layout::InputStreamTextSource::styleGetDominantBaseline() const
+{
+ return ((SPCSSBaseline)style->dominant_baseline.computed);
+}
+
static Layout::Alignment text_anchor_to_alignment(unsigned anchor, Layout::Direction para_direction)
{
switch (anchor) {
diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h
index c923cc0dc..97a05bde8 100644
--- a/src/libnrtype/Layout-TNG.h
+++ b/src/libnrtype/Layout-TNG.h
@@ -723,6 +723,7 @@ private:
font_instance *styleGetFontInstance() const;
Direction styleGetBlockProgression() const;
SPCSSTextOrientation styleGetTextOrientation() const;
+ SPCSSBaseline styleGetDominantBaseline() const;
Alignment styleGetAlignment(Direction para_direction, bool try_text_align) const;
};
@@ -769,6 +770,14 @@ private:
return SP_CSS_TEXT_ORIENTATION_MIXED;
}
+ /** The overall text-orientation of the whole flow. */
+ inline SPCSSBaseline _blockBaseline() const
+ {
+ if(!_input_stream.empty())
+ return static_cast<InputStreamTextSource*>(_input_stream.front())->styleGetDominantBaseline();
+ return SP_CSS_BASELINE_AUTO;
+ }
+
/** so that LEFT_TO_RIGHT == RIGHT_TO_LEFT but != TOP_TO_BOTTOM */
static bool _directions_are_orthogonal(Direction d1, Direction d2);