| OLD | NEW |
| 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/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
| 10 #include "base/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
| 11 #include "third_party/harfbuzz-ng/src/hb-icu.h" | |
| 12 #include "third_party/harfbuzz-ng/src/hb.h" | 11 #include "third_party/harfbuzz-ng/src/hb.h" |
| 13 #include "third_party/icu/source/common/unicode/ubidi.h" | 12 #include "third_party/icu/source/common/unicode/ubidi.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "third_party/skia/include/core/SkTypeface.h" | 14 #include "third_party/skia/include/core/SkTypeface.h" |
| 16 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/utf16_indexing.h" | 16 #include "ui/gfx/utf16_indexing.h" |
| 18 | 17 |
| 19 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 20 #include "ui/gfx/font_smoothing_win.h" | 19 #include "ui/gfx/font_smoothing_win.h" |
| 21 #endif | 20 #endif |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 while (char_iterator.Advance()) { | 306 while (char_iterator.Advance()) { |
| 308 ScriptSetIntersect(char_iterator.get(), scripts, &scripts_size); | 307 ScriptSetIntersect(char_iterator.get(), scripts, &scripts_size); |
| 309 if (scripts_size == 0U) | 308 if (scripts_size == 0U) |
| 310 return char_iterator.array_pos(); | 309 return char_iterator.array_pos(); |
| 311 *script = scripts[0]; | 310 *script = scripts[0]; |
| 312 } | 311 } |
| 313 | 312 |
| 314 return length; | 313 return length; |
| 315 } | 314 } |
| 316 | 315 |
| 316 // A port of hb_icu_script_to_script because harfbuzz on CrOS is built without |
| 317 // hb-icu. See http://crbug.com/356929 |
| 318 inline hb_script_t ICUScriptToHBScript(UScriptCode script) { |
| 319 if (script == USCRIPT_INVALID_CODE) |
| 320 return HB_SCRIPT_INVALID; |
| 321 return hb_script_from_string(uscript_getShortName(script), -1); |
| 322 } |
| 323 |
| 317 } // namespace | 324 } // namespace |
| 318 | 325 |
| 319 namespace internal { | 326 namespace internal { |
| 320 | 327 |
| 321 TextRunHarfBuzz::TextRunHarfBuzz() | 328 TextRunHarfBuzz::TextRunHarfBuzz() |
| 322 : width(0), | 329 : width(0), |
| 323 preceding_run_widths(0), | 330 preceding_run_widths(0), |
| 324 direction(UBIDI_LTR), | 331 direction(UBIDI_LTR), |
| 325 level(0), | 332 level(0), |
| 326 script(USCRIPT_INVALID_CODE), | 333 script(USCRIPT_INVALID_CODE), |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 | 908 |
| 902 hb_font_t* harfbuzz_font = CreateHarfBuzzFont(run->skia_face.get(), | 909 hb_font_t* harfbuzz_font = CreateHarfBuzzFont(run->skia_face.get(), |
| 903 run->font_size); | 910 run->font_size); |
| 904 | 911 |
| 905 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz | 912 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz |
| 906 // buffer holds our text, run information to be used by the shaping engine, | 913 // buffer holds our text, run information to be used by the shaping engine, |
| 907 // and the resulting glyph data. | 914 // and the resulting glyph data. |
| 908 hb_buffer_t* buffer = hb_buffer_create(); | 915 hb_buffer_t* buffer = hb_buffer_create(); |
| 909 hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16*>(text.c_str()), | 916 hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16*>(text.c_str()), |
| 910 text.length(), run->range.start(), run->range.length()); | 917 text.length(), run->range.start(), run->range.length()); |
| 911 hb_buffer_set_script(buffer, hb_icu_script_to_script(run->script)); | 918 hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script)); |
| 912 hb_buffer_set_direction(buffer, | 919 hb_buffer_set_direction(buffer, |
| 913 run->direction == UBIDI_LTR ? HB_DIRECTION_LTR : HB_DIRECTION_RTL); | 920 run->direction == UBIDI_LTR ? HB_DIRECTION_LTR : HB_DIRECTION_RTL); |
| 914 // TODO(ckocagil): Should we determine the actual language? | 921 // TODO(ckocagil): Should we determine the actual language? |
| 915 hb_buffer_set_language(buffer, hb_language_get_default()); | 922 hb_buffer_set_language(buffer, hb_language_get_default()); |
| 916 | 923 |
| 917 // Shape the text. | 924 // Shape the text. |
| 918 hb_shape(harfbuzz_font, buffer, NULL, 0); | 925 hb_shape(harfbuzz_font, buffer, NULL, 0); |
| 919 | 926 |
| 920 // Populate the run fields with the resulting glyph data in the buffer. | 927 // Populate the run fields with the resulting glyph data in the buffer. |
| 921 unsigned int glyph_count = 0; | 928 unsigned int glyph_count = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 936 run->positions[i].set(run->width + x_offset, y_offset); | 943 run->positions[i].set(run->width + x_offset, y_offset); |
| 937 run->width += | 944 run->width += |
| 938 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); | 945 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
| 939 } | 946 } |
| 940 | 947 |
| 941 hb_buffer_destroy(buffer); | 948 hb_buffer_destroy(buffer); |
| 942 hb_font_destroy(harfbuzz_font); | 949 hb_font_destroy(harfbuzz_font); |
| 943 } | 950 } |
| 944 | 951 |
| 945 } // namespace gfx | 952 } // namespace gfx |
| OLD | NEW |