summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 19:52:18 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 19:52:18 +0000
commit54d32cc876a0c690f3201acc27efea3dca74e7c2 (patch)
treea8b16246c15f78afa4d42641cc98e019bf8851f6
parent1403db3e8173e661a507f7e4b561d3d1cfb6c82f (diff)
downloadchromium_src-54d32cc876a0c690f3201acc27efea3dca74e7c2.zip
chromium_src-54d32cc876a0c690f3201acc27efea3dca74e7c2.tar.gz
chromium_src-54d32cc876a0c690f3201acc27efea3dca74e7c2.tar.bz2
Add diagonal strike support in RenderText
BUG=111125 TEST=manual Review URL: https://chromiumcodereview.appspot.com/9234052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119478 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc4
-rw-r--r--ui/gfx/render_text.cc24
-rw-r--r--ui/gfx/render_text.h4
-rw-r--r--ui/gfx/render_text_linux.cc13
-rw-r--r--ui/gfx/render_text_win.cc13
-rw-r--r--ui/gfx/render_text_win.h1
6 files changed, 39 insertions, 20 deletions
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index a738409..0320abe 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -124,11 +124,11 @@ void ApplyURLStyle(views::Textfield* textfield,
size_t start,
size_t end,
SkColor color,
- bool strike) {
+ bool diagonal_strike) {
gfx::StyleRange style;
style.foreground = color;
style.range = ui::Range(start, end);
- style.strike = strike;
+ style.diagonal_strike = diagonal_strike;
textfield->ApplyStyleRange(style);
}
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index f61ddc9..416e96d 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -239,13 +239,18 @@ void SkiaTextRenderer::DrawPosText(const SkPoint* pos,
// Based on |SkCanvas::DrawTextDecorations()| and constants from:
// third_party/skia/src/core/SkTextFormatParams.h
void SkiaTextRenderer::DrawDecorations(int x, int y, int width,
- bool underline, bool strike) {
+ const StyleRange& style) {
+ if (!style.underline && !style.strike && !style.diagonal_strike)
+ return;
+
// Fraction of the text size to lower a strike through below the baseline.
const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21);
// Fraction of the text size to lower an underline below the baseline.
const SkScalar kUnderlineOffset = (SK_Scalar1 / 9);
// Fraction of the text size to use for a strike through or under-line.
const SkScalar kLineThickness = (SK_Scalar1 / 18);
+ // Fraction of the text size to use for a top margin of a diagonal strike.
+ const SkScalar kDiagonalStrikeThroughMarginOffset = (SK_Scalar1 / 4);
SkScalar text_size = paint_.getTextSize();
SkScalar height = SkScalarMul(text_size, kLineThickness);
@@ -254,18 +259,30 @@ void SkiaTextRenderer::DrawDecorations(int x, int y, int width,
r.fLeft = x;
r.fRight = x + width;
- if (underline) {
+ if (style.underline) {
SkScalar offset = SkScalarMulAdd(text_size, kUnderlineOffset, y);
r.fTop = offset;
r.fBottom = offset + height;
canvas_skia_->drawRect(r, paint_);
}
- if (strike) {
+ if (style.strike) {
SkScalar offset = SkScalarMulAdd(text_size, kStrikeThroughOffset, y);
r.fTop = offset;
r.fBottom = offset + height;
canvas_skia_->drawRect(r, paint_);
}
+ if (style.diagonal_strike) {
+ SkScalar offset =
+ SkScalarMul(text_size, kDiagonalStrikeThroughMarginOffset);
+ SkPaint paint(paint_);
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setStrokeWidth(height);
+ canvas_skia_->drawLine(
+ SkIntToScalar(x), SkIntToScalar(y) - text_size + offset,
+ SkIntToScalar(x + width), SkIntToScalar(y),
+ paint);
+ }
}
} // namespace internal
@@ -275,6 +292,7 @@ StyleRange::StyleRange()
: foreground(SK_ColorBLACK),
font_style(gfx::Font::NORMAL),
strike(false),
+ diagonal_strike(false),
underline(false) {
}
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 21fe484..db98b84 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -27,6 +27,7 @@ namespace gfx {
class Canvas;
class RenderTextTest;
+struct StyleRange;
namespace internal {
@@ -46,7 +47,7 @@ class SkiaTextRenderer {
void DrawPosText(const SkPoint* pos,
const uint16* glyphs,
size_t glyph_count);
- void DrawDecorations(int x, int y, int width, bool underline, bool strike);
+ void DrawDecorations(int x, int y, int width, const StyleRange& style);
private:
SkCanvas* canvas_skia_;
@@ -65,6 +66,7 @@ struct UI_EXPORT StyleRange {
// A gfx::Font::FontStyle flag to specify bold and italic styles.
int font_style;
bool strike;
+ bool diagonal_strike;
bool underline;
ui::Range range;
};
diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc
index 14bf1f6..133bd4e 100644
--- a/ui/gfx/render_text_linux.cc
+++ b/ui/gfx/render_text_linux.cc
@@ -442,11 +442,7 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) {
renderer.SetForegroundColor(styles[style].foreground);
renderer.SetFontStyle(styles[style].font_style);
renderer.DrawPosText(&pos[start], &glyphs[start], i - start);
- if (styles[style].underline || styles[style].strike) {
- renderer.DrawDecorations(start_x, y, glyph_x - start_x,
- styles[style].underline,
- styles[style].strike);
- }
+ renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]);
start = i;
start_x = glyph_x;
@@ -462,12 +458,7 @@ void RenderTextLinux::DrawVisualText(Canvas* canvas) {
renderer.SetForegroundColor(styles[style].foreground);
renderer.SetFontStyle(styles[style].font_style);
renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start);
- if (styles[style].underline || styles[style].strike) {
- renderer.DrawDecorations(start_x, y, glyph_x - start_x,
- styles[style].underline,
- styles[style].strike);
- }
-
+ renderer.DrawDecorations(start_x, y, glyph_x - start_x, styles[style]);
x = glyph_x;
}
}
diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc
index 692d8e3..182c9ad 100644
--- a/ui/gfx/render_text_win.cc
+++ b/ui/gfx/render_text_win.cc
@@ -470,9 +470,15 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) {
renderer.SetFont(run->font);
renderer.SetForegroundColor(run->foreground);
renderer.DrawPosText(&pos[0], run->glyphs.get(), run->glyph_count);
-
- if (run->underline || run->strike)
- renderer.DrawDecorations(x, y, run->width, run->underline, run->strike);
+ // TODO(oshima|msw): Consider refactoring StyleRange into Style
+ // class and StyleRange containing Style, and use Style class in
+ // TextRun class. This may conflict with msw's comment in
+ // TextRun, so please consult with msw when refactoring.
+ StyleRange style;
+ style.strike = run->strike;
+ style.diagonal_strike = run->diagonal_strike;
+ style.underline = run->underline;
+ renderer.DrawDecorations(x, y, run->width, style);
x = glyph_x;
}
@@ -571,6 +577,7 @@ void RenderTextWin::ItemizeLogicalText() {
run->font = GetFont().DeriveFont(0, style->font_style);
run->foreground = style->foreground;
run->strike = style->strike;
+ run->diagonal_strike = style->diagonal_strike;
run->underline = style->underline;
run->script_analysis = script_item->a;
diff --git a/ui/gfx/render_text_win.h b/ui/gfx/render_text_win.h
index f3962d7..f2c3d72 100644
--- a/ui/gfx/render_text_win.h
+++ b/ui/gfx/render_text_win.h
@@ -30,6 +30,7 @@ struct TextRun {
// A gfx::Font::FontStyle flag to specify bold and italic styles.
int font_style;
bool strike;
+ bool diagonal_strike;
bool underline;
int width;