Commit 4355e675 authored by Jun Mukai's avatar Jun Mukai

Revert "adding baseline options for super/sub scripting"

This reverts commit eefeef59.

Revert reason: failure on WinXP builder

BUG=459812
TBR=dschuyler@chromium.org, msw@chromium.org

Review URL: https://codereview.chromium.org/989853002

Cr-Commit-Position: refs/heads/master@{#319559}
parent da8e162b
...@@ -174,25 +174,6 @@ SkPaint::Hinting FontRenderParamsHintingToSkPaintHinting( ...@@ -174,25 +174,6 @@ SkPaint::Hinting FontRenderParamsHintingToSkPaintHinting(
return SkPaint::kNo_Hinting; return SkPaint::kNo_Hinting;
} }
// Make sure ranges don't break text graphemes. If a range in |break_list|
// does break a grapheme in |render_text|, the range will be slightly
// extended to encompass the grapheme.
template <typename T>
void RestoreBreakList(RenderText* render_text, BreakList<T>& break_list) {
break_list.SetMax(render_text->text().length());
Range range;
while (range.end() < break_list.max()) {
const auto& current_break = break_list.GetBreak(range.end());
range = break_list.GetRange(current_break);
if (range.end() < break_list.max() &&
!render_text->IsValidCursorIndex(range.end())) {
range.set_end(
render_text->IndexOfAdjacentGrapheme(range.end(), CURSOR_FORWARD));
break_list.ApplyValue(current_break->second, range);
}
}
}
} // namespace } // namespace
namespace internal { namespace internal {
...@@ -368,11 +349,10 @@ void SkiaTextRenderer::DiagonalStrike::Draw() { ...@@ -368,11 +349,10 @@ void SkiaTextRenderer::DiagonalStrike::Draw() {
} }
StyleIterator::StyleIterator(const BreakList<SkColor>& colors, StyleIterator::StyleIterator(const BreakList<SkColor>& colors,
const BreakList<BaselineStyle>& baselines, const std::vector<BreakList<bool> >& styles)
const std::vector<BreakList<bool>>& styles) : colors_(colors),
: colors_(colors), baselines_(baselines), styles_(styles) { styles_(styles) {
color_ = colors_.breaks().begin(); color_ = colors_.breaks().begin();
baseline_ = baselines_.breaks().begin();
for (size_t i = 0; i < styles_.size(); ++i) for (size_t i = 0; i < styles_.size(); ++i)
style_.push_back(styles_[i].breaks().begin()); style_.push_back(styles_[i].breaks().begin());
} }
...@@ -381,7 +361,6 @@ StyleIterator::~StyleIterator() {} ...@@ -381,7 +361,6 @@ StyleIterator::~StyleIterator() {}
Range StyleIterator::GetRange() const { Range StyleIterator::GetRange() const {
Range range(colors_.GetRange(color_)); Range range(colors_.GetRange(color_));
range = range.Intersect(baselines_.GetRange(baseline_));
for (size_t i = 0; i < NUM_TEXT_STYLES; ++i) for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
range = range.Intersect(styles_[i].GetRange(style_[i])); range = range.Intersect(styles_[i].GetRange(style_[i]));
return range; return range;
...@@ -389,7 +368,6 @@ Range StyleIterator::GetRange() const { ...@@ -389,7 +368,6 @@ Range StyleIterator::GetRange() const {
void StyleIterator::UpdatePosition(size_t position) { void StyleIterator::UpdatePosition(size_t position) {
color_ = colors_.GetBreak(position); color_ = colors_.GetBreak(position);
baseline_ = baselines_.GetBreak(position);
for (size_t i = 0; i < NUM_TEXT_STYLES; ++i) for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
style_[i] = styles_[i].GetBreak(position); style_[i] = styles_[i].GetBreak(position);
} }
...@@ -445,13 +423,11 @@ void RenderText::SetText(const base::string16& text) { ...@@ -445,13 +423,11 @@ void RenderText::SetText(const base::string16& text) {
return; return;
text_ = text; text_ = text;
// Adjust ranged styles, baselines, and colors to accommodate a new text // Adjust ranged styles and colors to accommodate a new text length.
// length. Clear style ranges as they might break new text graphemes and apply // Clear style ranges as they might break new text graphemes and apply
// the first style to the whole text instead. // the first style to the whole text instead.
const size_t text_length = text_.length(); const size_t text_length = text_.length();
colors_.SetMax(text_length); colors_.SetMax(text_length);
baselines_.SetValue(baselines_.breaks().begin()->second);
baselines_.SetMax(text_length);
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) { for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) {
BreakList<bool>& break_list = styles_[style]; BreakList<bool>& break_list = styles_[style];
break_list.SetValue(break_list.breaks().begin()->second); break_list.SetValue(break_list.breaks().begin()->second);
...@@ -694,14 +670,6 @@ void RenderText::ApplyColor(SkColor value, const Range& range) { ...@@ -694,14 +670,6 @@ void RenderText::ApplyColor(SkColor value, const Range& range) {
colors_.ApplyValue(value, range); colors_.ApplyValue(value, range);
} }
void RenderText::SetBaselineStyle(BaselineStyle value) {
baselines_.SetValue(value);
}
void RenderText::ApplyBaselineStyle(BaselineStyle value, const Range& range) {
baselines_.ApplyValue(value, range);
}
void RenderText::SetStyle(TextStyle style, bool value) { void RenderText::SetStyle(TextStyle style, bool value) {
styles_[style].SetValue(value); styles_[style].SetValue(value);
...@@ -942,7 +910,6 @@ RenderText::RenderText() ...@@ -942,7 +910,6 @@ RenderText::RenderText()
focused_(false), focused_(false),
composition_range_(Range::InvalidRange()), composition_range_(Range::InvalidRange()),
colors_(kDefaultColor), colors_(kDefaultColor),
baselines_(NORMAL_BASELINE),
styles_(NUM_TEXT_STYLES), styles_(NUM_TEXT_STYLES),
composition_and_selection_styles_applied_(false), composition_and_selection_styles_applied_(false),
obscured_(false), obscured_(false),
...@@ -1316,7 +1283,6 @@ base::string16 RenderText::Elide(const base::string16& text, ...@@ -1316,7 +1283,6 @@ base::string16 RenderText::Elide(const base::string16& text,
render_text->SetCursorEnabled(cursor_enabled_); render_text->SetCursorEnabled(cursor_enabled_);
render_text->set_truncate_length(truncate_length_); render_text->set_truncate_length(truncate_length_);
render_text->styles_ = styles_; render_text->styles_ = styles_;
render_text->baselines_ = baselines_;
render_text->colors_ = colors_; render_text->colors_ = colors_;
if (text_width == 0) { if (text_width == 0) {
render_text->SetText(text); render_text->SetText(text);
...@@ -1370,11 +1336,24 @@ base::string16 RenderText::Elide(const base::string16& text, ...@@ -1370,11 +1336,24 @@ base::string16 RenderText::Elide(const base::string16& text,
render_text->SetText(new_text); render_text->SetText(new_text);
} }
// Restore styles and baselines without breaking multi-character graphemes. // Restore styles. Make sure style ranges don't break new text graphemes.
render_text->styles_ = styles_; render_text->styles_ = styles_;
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) {
RestoreBreakList(render_text.get(), render_text->styles_[style]); BreakList<bool>& break_list = render_text->styles_[style];
RestoreBreakList(render_text.get(), baselines_); break_list.SetMax(render_text->text_.length());
Range range;
while (range.end() < break_list.max()) {
BreakList<bool>::const_iterator current_break =
break_list.GetBreak(range.end());
range = break_list.GetRange(current_break);
if (range.end() < break_list.max() &&
!render_text->IsValidCursorIndex(range.end())) {
range.set_end(render_text->IndexOfAdjacentGrapheme(range.end(),
CURSOR_FORWARD));
break_list.ApplyValue(current_break->second, range);
}
}
}
// We check the width of the whole desired string at once to ensure we // We check the width of the whole desired string at once to ensure we
// handle kerning/ligatures/etc. correctly. // handle kerning/ligatures/etc. correctly.
......
...@@ -109,17 +109,15 @@ class GFX_EXPORT SkiaTextRenderer { ...@@ -109,17 +109,15 @@ class GFX_EXPORT SkiaTextRenderer {
DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer);
}; };
// Internal helper class used to iterate colors, baselines, and styles. // Internal helper class used by derived classes to iterate colors and styles.
class StyleIterator { class StyleIterator {
public: public:
StyleIterator(const BreakList<SkColor>& colors, StyleIterator(const BreakList<SkColor>& colors,
const BreakList<BaselineStyle>& baselines, const std::vector<BreakList<bool> >& styles);
const std::vector<BreakList<bool>>& styles);
~StyleIterator(); ~StyleIterator();
// Get the colors and styles at the current iterator position. // Get the colors and styles at the current iterator position.
SkColor color() const { return color_->second; } SkColor color() const { return color_->second; }
BaselineStyle baseline() const { return baseline_->second; }
bool style(TextStyle s) const { return style_[s]->second; } bool style(TextStyle s) const { return style_[s]->second; }
// Get the intersecting range of the current iterator set. // Get the intersecting range of the current iterator set.
...@@ -130,11 +128,9 @@ class StyleIterator { ...@@ -130,11 +128,9 @@ class StyleIterator {
private: private:
BreakList<SkColor> colors_; BreakList<SkColor> colors_;
BreakList<BaselineStyle> baselines_;
std::vector<BreakList<bool> > styles_; std::vector<BreakList<bool> > styles_;
BreakList<SkColor>::const_iterator color_; BreakList<SkColor>::const_iterator color_;
BreakList<BaselineStyle>::const_iterator baseline_;
std::vector<BreakList<bool>::const_iterator> style_; std::vector<BreakList<bool>::const_iterator> style_;
DISALLOW_COPY_AND_ASSIGN(StyleIterator); DISALLOW_COPY_AND_ASSIGN(StyleIterator);
...@@ -336,11 +332,6 @@ class GFX_EXPORT RenderText { ...@@ -336,11 +332,6 @@ class GFX_EXPORT RenderText {
void SetColor(SkColor value); void SetColor(SkColor value);
void ApplyColor(SkColor value, const Range& range); void ApplyColor(SkColor value, const Range& range);
// Set the baseline style over the entire text or a logical character range.
// The |range| should be valid, non-reversed, and within [0, text().length()].
void SetBaselineStyle(BaselineStyle value);
void ApplyBaselineStyle(BaselineStyle value, const Range& range);
// Set various text styles over the entire text or a logical character range. // Set various text styles over the entire text or a logical character range.
// The respective |style| is applied if |value| is true, or removed if false. // The respective |style| is applied if |value| is true, or removed if false.
// The |range| should be valid, non-reversed, and within [0, text().length()]. // The |range| should be valid, non-reversed, and within [0, text().length()].
...@@ -465,7 +456,6 @@ class GFX_EXPORT RenderText { ...@@ -465,7 +456,6 @@ class GFX_EXPORT RenderText {
bool text_elided() const { return text_elided_; } bool text_elided() const { return text_elided_; }
const BreakList<SkColor>& colors() const { return colors_; } const BreakList<SkColor>& colors() const { return colors_; }
const BreakList<BaselineStyle>& baselines() const { return baselines_; }
const std::vector<BreakList<bool> >& styles() const { return styles_; } const std::vector<BreakList<bool> >& styles() const { return styles_; }
const std::vector<internal::Line>& lines() const { return lines_; } const std::vector<internal::Line>& lines() const { return lines_; }
...@@ -702,11 +692,10 @@ class GFX_EXPORT RenderText { ...@@ -702,11 +692,10 @@ class GFX_EXPORT RenderText {
// Composition text range. // Composition text range.
Range composition_range_; Range composition_range_;
// Color, baseline, and style breaks, used to modify ranges of text. // Color and style breaks, used to color and stylize ranges of text.
// BreakList positions are stored with text indices, not display indices. // BreakList positions are stored with text indices, not display indices.
// TODO(msw): Expand to support cursor, selection, background, etc. colors. // TODO(msw): Expand to support cursor, selection, background, etc. colors.
BreakList<SkColor> colors_; BreakList<SkColor> colors_;
BreakList<BaselineStyle> baselines_;
std::vector<BreakList<bool> > styles_; std::vector<BreakList<bool> > styles_;
// Breaks saved without temporary composition and selection styling. // Breaks saved without temporary composition and selection styling.
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/font_fallback.h" #include "ui/gfx/font_fallback.h"
#include "ui/gfx/font_render_params.h" #include "ui/gfx/font_render_params.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/harfbuzz_font_skia.h" #include "ui/gfx/harfbuzz_font_skia.h"
#include "ui/gfx/range/range_f.h" #include "ui/gfx/range/range_f.h"
#include "ui/gfx/utf16_indexing.h" #include "ui/gfx/utf16_indexing.h"
...@@ -422,7 +421,6 @@ class HarfBuzzLineBreaker { ...@@ -422,7 +421,6 @@ class HarfBuzzLineBreaker {
paint.getFontMetrics(&metrics); paint.getFontMetrics(&metrics);
line->size.set_width(line->size.width() + width); line->size.set_width(line->size.width() + width);
// TODO(dschuyler): Account for stylized baselines in string sizing.
max_descent_ = std::max(max_descent_, metrics.fDescent); max_descent_ = std::max(max_descent_, metrics.fDescent);
// fAscent is always negative. // fAscent is always negative.
max_ascent_ = std::max(max_ascent_, -metrics.fAscent); max_ascent_ = std::max(max_ascent_, -metrics.fAscent);
...@@ -483,13 +481,10 @@ TextRunHarfBuzz::TextRunHarfBuzz() ...@@ -483,13 +481,10 @@ TextRunHarfBuzz::TextRunHarfBuzz()
script(USCRIPT_INVALID_CODE), script(USCRIPT_INVALID_CODE),
glyph_count(static_cast<size_t>(-1)), glyph_count(static_cast<size_t>(-1)),
font_size(0), font_size(0),
baseline_offset(0),
baseline_type(0),
font_style(0), font_style(0),
strike(false), strike(false),
diagonal_strike(false), diagonal_strike(false),
underline(false) { underline(false) {}
}
TextRunHarfBuzz::~TextRunHarfBuzz() {} TextRunHarfBuzz::~TextRunHarfBuzz() {}
...@@ -1035,7 +1030,7 @@ void RenderTextHarfBuzz::DrawVisualTextInternal( ...@@ -1035,7 +1030,7 @@ void RenderTextHarfBuzz::DrawVisualTextInternal(
(glyphs_range.start() - j) : (glyphs_range.start() - j) :
(glyphs_range.start() + j)]; (glyphs_range.start() + j)];
positions[j].offset(SkIntToScalar(origin.x()) + offset_x, positions[j].offset(SkIntToScalar(origin.x()) + offset_x,
SkIntToScalar(origin.y() + run.baseline_offset)); SkIntToScalar(origin.y()));
} }
for (BreakList<SkColor>::const_iterator it = for (BreakList<SkColor>::const_iterator it =
colors().GetBreak(segment.char_range.start()); colors().GetBreak(segment.char_range.start());
...@@ -1144,18 +1139,17 @@ void RenderTextHarfBuzz::ItemizeTextToRuns( ...@@ -1144,18 +1139,17 @@ void RenderTextHarfBuzz::ItemizeTextToRuns(
// Temporarily apply composition underlines and selection colors. // Temporarily apply composition underlines and selection colors.
ApplyCompositionAndSelectionStyles(); ApplyCompositionAndSelectionStyles();
// Build the run list from the script items and ranged styles and baselines. // Build the list of runs from the script items and ranged styles. Use an
// Use an empty color BreakList to avoid breaking runs at color boundaries. // empty color BreakList to avoid breaking runs at color boundaries.
BreakList<SkColor> empty_colors; BreakList<SkColor> empty_colors;
empty_colors.SetMax(text.length()); empty_colors.SetMax(text.length());
internal::StyleIterator style(empty_colors, baselines(), styles()); internal::StyleIterator style(empty_colors, styles());
for (size_t run_break = 0; run_break < text.length();) { for (size_t run_break = 0; run_break < text.length();) {
internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz;
run->range.set_start(run_break); run->range.set_start(run_break);
run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | run->font_style = (style.style(BOLD) ? Font::BOLD : 0) |
(style.style(ITALIC) ? Font::ITALIC : 0); (style.style(ITALIC) ? Font::ITALIC : 0);
run->baseline_type = style.baseline();
run->strike = style.style(STRIKE); run->strike = style.style(STRIKE);
run->diagonal_strike = style.style(DIAGONAL_STRIKE); run->diagonal_strike = style.style(DIAGONAL_STRIKE);
run->underline = style.style(UNDERLINE); run->underline = style.style(UNDERLINE);
...@@ -1224,31 +1218,6 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text, ...@@ -1224,31 +1218,6 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text,
const Font& primary_font = font_list().GetPrimaryFont(); const Font& primary_font = font_list().GetPrimaryFont();
const std::string primary_family = primary_font.GetFontName(); const std::string primary_family = primary_font.GetFontName();
run->font_size = primary_font.GetFontSize(); run->font_size = primary_font.GetFontSize();
run->baseline_offset = 0;
if (run->baseline_type != NORMAL_BASELINE) {
// Calculate a slightly smaller font. The ratio here is somewhat arbitrary.
// Proportions from 5/9 to 5/7 all look pretty good.
const float ratio = 5.0f / 9.0f;
run->font_size = gfx::ToRoundedInt(primary_font.GetFontSize() * ratio);
switch (run->baseline_type) {
case SUPERSCRIPT:
run->baseline_offset =
primary_font.GetCapHeight() - primary_font.GetHeight();
break;
case SUPERIOR:
run->baseline_offset =
gfx::ToRoundedInt(primary_font.GetCapHeight() * ratio) -
primary_font.GetCapHeight();
break;
case SUBSCRIPT:
run->baseline_offset =
primary_font.GetHeight() - primary_font.GetBaseline();
break;
case INFERIOR: // Fall through.
default:
break;
}
}
std::string best_family; std::string best_family;
FontRenderParams best_render_params; FontRenderParams best_render_params;
......
...@@ -70,8 +70,6 @@ struct GFX_EXPORT TextRunHarfBuzz { ...@@ -70,8 +70,6 @@ struct GFX_EXPORT TextRunHarfBuzz {
skia::RefPtr<SkTypeface> skia_face; skia::RefPtr<SkTypeface> skia_face;
FontRenderParams render_params; FontRenderParams render_params;
int font_size; int font_size;
int baseline_offset;
int baseline_type;
int font_style; int font_style;
bool strike; bool strike;
bool diagonal_strike; bool diagonal_strike;
......
...@@ -230,7 +230,7 @@ void RenderTextMac::ApplyStyles(CFMutableAttributedStringRef attr_string, ...@@ -230,7 +230,7 @@ void RenderTextMac::ApplyStyles(CFMutableAttributedStringRef attr_string,
attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)); attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks));
// https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html
internal::StyleIterator style(colors(), baselines(), styles()); internal::StyleIterator style(colors(), styles());
const size_t layout_text_length = GetDisplayText().length(); const size_t layout_text_length = GetDisplayText().length();
for (size_t i = 0, end = 0; i < layout_text_length; i = end) { for (size_t i = 0, end = 0; i < layout_text_length; i = end) {
end = TextIndexToDisplayIndex(style.GetRange().end()); end = TextIndexToDisplayIndex(style.GetRange().end());
......
This diff is collapsed.
...@@ -42,25 +42,6 @@ enum TextStyle { ...@@ -42,25 +42,6 @@ enum TextStyle {
NUM_TEXT_STYLES, NUM_TEXT_STYLES,
}; };
// Text baseline offset types.
// Figure of font metrics:
// +--------+--------+------------------------+-------------+
// | | | internal leading | SUPERSCRIPT |
// | | +------------+-----------| |
// | | ascent | | SUPERIOR |-------------+
// | height | | cap height |-----------|
// | | | | INFERIOR |-------------+
// | |--------+------------+-----------| |
// | | descent | SUBSCRIPT |
// +--------+---------------------------------+-------------+
enum BaselineStyle {
NORMAL_BASELINE = 0,
SUPERSCRIPT, // e.g. a mathematical exponent would be superscript.
SUPERIOR, // e.g. 8th, the "th" would be superior script.
INFERIOR, // e.g. 1/2, the "2" would be inferior ("1" is superior).
SUBSCRIPT, // e.g. H2O, the "2" would be subscript.
};
// Elision behaviors of text that exceeds constrained dimensions. // Elision behaviors of text that exceeds constrained dimensions.
enum ElideBehavior { enum ElideBehavior {
NO_ELIDE = 0, // Do not modify the text, it may overflow its available bounds. NO_ELIDE = 0, // Do not modify the text, it may overflow its available bounds.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment