Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: ui/gfx/render_text_harfbuzz.cc

Issue 408733002: Fix RenderTextHarfBuzz glyph offset regression. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text_harfbuzz.h" 5 #include "ui/gfx/render_text_harfbuzz.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/debug/leak_annotations.h" 9 #include "base/debug/leak_annotations.h"
10 #include "base/i18n/bidi_line_iterator.h" 10 #include "base/i18n/bidi_line_iterator.h"
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 1004
1005 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz 1005 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz
1006 // buffer holds our text, run information to be used by the shaping engine, 1006 // buffer holds our text, run information to be used by the shaping engine,
1007 // and the resulting glyph data. 1007 // and the resulting glyph data.
1008 hb_buffer_t* buffer = hb_buffer_create(); 1008 hb_buffer_t* buffer = hb_buffer_create();
1009 hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16*>(text.c_str()), 1009 hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16*>(text.c_str()),
1010 text.length(), run->range.start(), run->range.length()); 1010 text.length(), run->range.start(), run->range.length());
1011 hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script)); 1011 hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script));
1012 hb_buffer_set_direction(buffer, 1012 hb_buffer_set_direction(buffer,
1013 run->is_rtl ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); 1013 run->is_rtl ? HB_DIRECTION_RTL : HB_DIRECTION_LTR);
1014 // TODO(ckocagil): Should we call |hb_buffer_set_language()| here? 1014 // TODO(ckocagil): Should we call |hb_buffer_set_language()| here?
ckocagil 2014/07/19 23:35:21 Can you change this comment to the following 2 lin
msw 2014/07/20 00:08:20 Done.
1015 1015
1016 // Shape the text. 1016 // Shape the text.
1017 hb_shape(harfbuzz_font, buffer, NULL, 0); 1017 hb_shape(harfbuzz_font, buffer, NULL, 0);
1018 1018
1019 // Populate the run fields with the resulting glyph data in the buffer. 1019 // Populate the run fields with the resulting glyph data in the buffer.
1020 unsigned int glyph_count = 0; 1020 unsigned int glyph_count = 0;
1021 hb_glyph_info_t* infos = hb_buffer_get_glyph_infos(buffer, &glyph_count); 1021 hb_glyph_info_t* infos = hb_buffer_get_glyph_infos(buffer, &glyph_count);
1022 run->glyph_count = glyph_count; 1022 run->glyph_count = glyph_count;
1023 hb_glyph_position_t* hb_positions = 1023 hb_glyph_position_t* hb_positions =
1024 hb_buffer_get_glyph_positions(buffer, NULL); 1024 hb_buffer_get_glyph_positions(buffer, NULL);
1025 run->glyphs.reset(new uint16[run->glyph_count]); 1025 run->glyphs.reset(new uint16[run->glyph_count]);
1026 run->glyph_to_char.reset(new uint32[run->glyph_count]); 1026 run->glyph_to_char.reset(new uint32[run->glyph_count]);
1027 run->positions.reset(new SkPoint[run->glyph_count]); 1027 run->positions.reset(new SkPoint[run->glyph_count]);
1028 run->width = 0; 1028 run->width = 0;
1029 for (size_t i = 0; i < run->glyph_count; ++i) { 1029 for (size_t i = 0; i < run->glyph_count; ++i) {
1030 run->glyphs[i] = infos[i].codepoint; 1030 run->glyphs[i] = infos[i].codepoint;
1031 run->glyph_to_char[i] = infos[i].cluster; 1031 run->glyph_to_char[i] = infos[i].cluster;
1032 const int x_offset = 1032 const int x_offset =
1033 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_offset)); 1033 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_offset));
1034 const int y_offset = 1034 const int y_offset =
1035 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].y_offset)); 1035 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].y_offset));
1036 run->positions[i].set(run->width + x_offset, y_offset); 1036 run->positions[i].set(run->width + x_offset, -y_offset);
1037 run->width += 1037 run->width +=
1038 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); 1038 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance));
1039 } 1039 }
1040 1040
1041 hb_buffer_destroy(buffer); 1041 hb_buffer_destroy(buffer);
1042 hb_font_destroy(harfbuzz_font); 1042 hb_font_destroy(harfbuzz_font);
1043 } 1043 }
1044 1044
1045 } // namespace gfx 1045 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698