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

Side by Side Diff: chrome/renderer/print_web_view_helper_win.cc

Issue 9111042: Fix RTL and complex script title in print preview header/footer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #include "base/i18n/rtl.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
10 #include "base/process_util.h" 11 #include "base/process_util.h"
11 #include "base/win/scoped_gdi_object.h" 12 #include "base/win/scoped_gdi_object.h"
12 #include "base/win/scoped_hdc.h" 13 #include "base/win/scoped_hdc.h"
13 #include "base/win/scoped_select_object.h" 14 #include "base/win/scoped_select_object.h"
14 #include "chrome/common/print_messages.h" 15 #include "chrome/common/print_messages.h"
15 #include "printing/metafile.h" 16 #include "printing/metafile.h"
16 #include "printing/metafile_impl.h" 17 #include "printing/metafile_impl.h"
17 #include "printing/metafile_skia_wrapper.h" 18 #include "printing/metafile_skia_wrapper.h"
18 #include "printing/page_size_margins.h" 19 #include "printing/page_size_margins.h"
19 #include "printing/units.h" 20 #include "printing/units.h"
20 #include "skia/ext/vector_canvas.h" 21 #include "skia/ext/vector_canvas.h"
21 #include "skia/ext/platform_device.h" 22 #include "skia/ext/platform_device.h"
22 #include "third_party/skia/include/core/SkRefCnt.h" 23 #include "third_party/skia/include/core/SkRefCnt.h"
24 #include "third_party/skia/include/ports/SkTypeface_win.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
24 #include "ui/gfx/gdi_util.h" 26 #include "ui/gfx/gdi_util.h"
25 #include "ui/gfx/point.h" 27 #include "ui/gfx/point.h"
26 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
27 #include "ui/gfx/size.h" 29 #include "ui/gfx/size.h"
28 30
29 using printing::ConvertUnit; 31 using printing::ConvertUnit;
30 using printing::ConvertUnitDouble; 32 using printing::ConvertUnitDouble;
31 using printing::kPointsPerInch; 33 using printing::kPointsPerInch;
32 using printing::Metafile; 34 using printing::Metafile;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 shared_buf.Unmap(); 322 shared_buf.Unmap();
321 return false; 323 return false;
322 } 324 }
323 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 325 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
324 shared_buf.Unmap(); 326 shared_buf.Unmap();
325 327
326 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, 328 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
327 shared_mem_handle)); 329 shared_mem_handle));
328 return true; 330 return true;
329 } 331 }
332
333 #if defined(USE_SKIA)
334
335 // Uniscribe generation is very time consuming so a global cache for previous
336 // results are needed.
337 SCRIPT_CACHE PrintWebViewHelper::g_script_cache_;
338 SCRIPT_ANALYSIS PrintWebViewHelper::g_script_analysis_;
jungshik at Google 2012/01/06 22:38:45 In the past, we used to have UniscribeHelper class
xji 2012/01/07 01:21:15 Mike (msw@) implemented RenderText in Windows. The
339
340 // static
341 bool PrintWebViewHelper::ConvertTextToGlyphs(SkTypeface* typeface,
342 const string16& text,
343 std::vector<uint16_t>* glyphs) {
344 bool rtl = base::i18n::IsRTL() &&
345 base::i18n::StringContainsStrongRTLChars(text);
346 HRESULT hr = ScriptIsComplex(text.c_str(), text.size(), SIC_COMPLEX);
347 if (hr != S_OK && !rtl) {
348 return false; // Script is neither complex nor BiDi.
349 }
350
351 // Complex script handling started here.
352 std::vector<SCRIPT_ITEM> items;
353 int max_items = text.size();
354 int generated_items;
355 for (;;) {
356 items.resize(max_items);
357 hr = ScriptItemize(text.c_str(), text.size(), max_items - 1, NULL, NULL,
358 &items[0], &generated_items);
359 if (SUCCEEDED(hr)) {
360 items.resize(generated_items + 1);
361 break;
362 }
363 if (hr != E_OUTOFMEMORY) {
364 return false;
365 }
366 max_items *= 2;
367 }
368
369 std::vector<int> visual_to_logical(generated_items + 1);
370 std::vector<int> logical_to_visual(generated_items + 1);
371 std::vector<BYTE> directions(generated_items);
372 for (int i = 0; i < generated_items; ++i) {
373 directions[i] = items[i].a.s.uBidiLevel;
374 }
375
376 ScriptLayout(generated_items, &directions[0], &visual_to_logical[0],
377 &logical_to_visual[0]);
378 visual_to_logical.push_back(generated_items);
379 logical_to_visual.push_back(generated_items);
380
381 base::win::ScopedCreateDC dc(CreateCompatibleDC(GetDC(NULL)));
382 LOGFONT lf;
383 SkLOGFONTFromTypeface(typeface, &lf);
384 HFONT font_handle = CreateFontIndirect(&lf);
385 if (font_handle == NULL) {
386 return false;
387 }
388 SelectObject(dc.Get(), font_handle);
389
390 for (size_t i = 0; i < items.size() - 1; ++i) {
391 int index = logical_to_visual[i];
392 int input_length = items[index + 1].iCharPos - items[index].iCharPos;
393
394 // Initial size guess suggested by MSDN.
395 std::vector<WORD> logs(input_length);
396 int max_glyph_len = input_length * 3 / 2 + 16;
397 std::vector<WORD> glyph_buffer;
398 std::vector<SCRIPT_VISATTR> visattr;
399
400 for (;;) {
401 int glyphs_used;
402 glyph_buffer.resize(max_glyph_len);
403 visattr.resize(max_glyph_len);
404 items[index].a.fLogicalOrder = FALSE;
405 hr = ScriptShape(dc, &g_script_cache_, &text[items[index].iCharPos],
406 input_length, max_glyph_len, &(items[index].a),
407 &glyph_buffer[0], &logs[0], &visattr[0], &glyphs_used);
408 if (SUCCEEDED(hr)) {
409 // We are not supposed to handle Kashidas in Arabic, so reverting the
410 // glyph order shall be good enough for all RTLs.
411 glyph_buffer.resize(glyphs_used);
412 glyphs->insert(glyphs->end(), glyph_buffer.begin(),glyph_buffer.end());
413 break;
414 }
415
416 if (hr == E_PENDING) {
417 // keep waiting
418 } else if (hr != E_OUTOFMEMORY) {
419 return false;
420 }
421
jungshik at Google 2012/01/06 22:38:45 After calling ScriptShape, ScriptPlace (?) has to
422 max_glyph_len *= 2;
423 }
424 }
425
426 return true;
427 }
428 #endif
OLDNEW
« chrome/renderer/print_web_view_helper.cc ('K') | « chrome/renderer/print_web_view_helper_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698