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

Side by Side Diff: content/browser/renderer_host/render_sandbox_host_linux.cc

Issue 213793003: Linux: Do better font substitution for Chinese characters. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_sandbox_host_linux.h" 5 #include "content/browser/renderer_host/render_sandbox_host_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <fontconfig/fontconfig.h> 8 #include <fontconfig/fontconfig.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <sys/poll.h> 10 #include <sys/poll.h>
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (!pickle.ReadString(&iter, &face) || 400 if (!pickle.ReadString(&iter, &face) ||
401 face.empty() || 401 face.empty() ||
402 !pickle.ReadBool(&iter, &is_bold) || 402 !pickle.ReadBool(&iter, &is_bold) ||
403 !pickle.ReadBool(&iter, &is_italic) || 403 !pickle.ReadBool(&iter, &is_italic) ||
404 !pickle.ReadUInt32(&iter, &charset) || 404 !pickle.ReadUInt32(&iter, &charset) ||
405 !pickle.ReadUInt32(&iter, &fallback_family)) { 405 !pickle.ReadUInt32(&iter, &fallback_family)) {
406 return; 406 return;
407 } 407 }
408 408
409 FcLangSet* langset = FcLangSetCreate(); 409 FcLangSet* langset = FcLangSetCreate();
410 MSCharSetToFontconfig(langset, charset); 410 bool is_lgc = MSCharSetToFontconfig(langset, charset);
411 411
412 FcPattern* pattern = FcPatternCreate(); 412 FcPattern* pattern = FcPatternCreate();
413 // TODO(agl): FC_FAMILy needs to change
414 FcPatternAddString(pattern, FC_FAMILY, 413 FcPatternAddString(pattern, FC_FAMILY,
415 reinterpret_cast<const FcChar8*>(face.c_str())); 414 reinterpret_cast<const FcChar8*>(face.c_str()));
416 415
416 // TODO(thestig) Check if we can access Chrome's per-script font preference
417 // here and select better default fonts for non-LGC case.
417 std::string generic_font_name; 418 std::string generic_font_name;
418 switch (fallback_family) { 419 if (is_lgc) {
419 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: 420 switch (fallback_family) {
420 generic_font_name = "Times New Roman"; 421 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF:
421 break; 422 generic_font_name = "Times New Roman";
422 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: 423 break;
423 generic_font_name = "Arial"; 424 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF:
424 break; 425 generic_font_name = "Arial";
425 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: 426 break;
426 generic_font_name = "Courier New"; 427 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE:
427 break; 428 generic_font_name = "Courier New";
429 break;
430 }
428 } 431 }
429 if (!generic_font_name.empty()) { 432 if (!generic_font_name.empty()) {
430 const FcChar8* fc_generic_font_name = 433 const FcChar8* fc_generic_font_name =
431 reinterpret_cast<const FcChar8*>(generic_font_name.c_str()); 434 reinterpret_cast<const FcChar8*>(generic_font_name.c_str());
432 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name); 435 FcPatternAddString(pattern, FC_FAMILY, fc_generic_font_name);
433 } 436 }
434 437
435 if (is_bold) 438 if (is_bold)
436 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); 439 FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
437 if (is_italic) 440 if (is_italic)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 SendRendererReply(fds, reply, font_fd); 543 SendRendererReply(fds, reply, font_fd);
541 544
542 if (font_fd >= 0) { 545 if (font_fd >= 0) {
543 if (IGNORE_EINTR(close(font_fd)) < 0) 546 if (IGNORE_EINTR(close(font_fd)) < 0)
544 PLOG(ERROR) << "close"; 547 PLOG(ERROR) << "close";
545 } 548 }
546 } 549 }
547 550
548 // MSCharSetToFontconfig translates a Microsoft charset identifier to a 551 // MSCharSetToFontconfig translates a Microsoft charset identifier to a
549 // fontconfig language set by appending to |langset|. 552 // fontconfig language set by appending to |langset|.
550 static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { 553 // Returns true if |langset| is Latin/Greek/Cyrillic.
554 static bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
551 // We have need to translate raw fdwCharSet values into terms that 555 // We have need to translate raw fdwCharSet values into terms that
552 // fontconfig can understand. (See the description of fdwCharSet in the MSDN 556 // fontconfig can understand. (See the description of fdwCharSet in the MSDN
553 // documentation for CreateFont: 557 // documentation for CreateFont:
554 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx ) 558 // http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx )
555 // 559 //
556 // Although the argument is /called/ 'charset', the actual values conflate 560 // Although the argument is /called/ 'charset', the actual values conflate
557 // character sets (which are sets of Unicode code points) and character 561 // character sets (which are sets of Unicode code points) and character
558 // encodings (which are algorithms for turning a series of bits into a 562 // encodings (which are algorithms for turning a series of bits into a
559 // series of code points.) Sometimes the values will name a language, 563 // series of code points.) Sometimes the values will name a language,
560 // sometimes they'll name an encoding. In the latter case I'm assuming that 564 // sometimes they'll name an encoding. In the latter case I'm assuming that
561 // they mean the set of code points in the domain of that encoding. 565 // they mean the set of code points in the domain of that encoding.
562 // 566 //
563 // fontconfig deals with ISO 639-1 language codes: 567 // fontconfig deals with ISO 639-1 language codes:
564 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes 568 // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
565 // 569 //
566 // So, for each of the documented fdwCharSet values I've had to take a 570 // So, for each of the documented fdwCharSet values I've had to take a
567 // guess at the set of ISO 639-1 languages intended. 571 // guess at the set of ISO 639-1 languages intended.
568 572
573 bool is_lgc = false;
569 switch (fdwCharSet) { 574 switch (fdwCharSet) {
570 case NPCharsetAnsi: 575 case NPCharsetAnsi:
571 // These values I don't really know what to do with, so I'm going to map 576 // These values I don't really know what to do with, so I'm going to map
572 // them to English also. 577 // them to English also.
573 case NPCharsetDefault: 578 case NPCharsetDefault:
574 case NPCharsetMac: 579 case NPCharsetMac:
575 case NPCharsetOEM: 580 case NPCharsetOEM:
576 case NPCharsetSymbol: 581 case NPCharsetSymbol:
582 is_lgc = true;
577 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); 583 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en"));
578 break; 584 break;
579 case NPCharsetBaltic: 585 case NPCharsetBaltic:
580 // The three baltic languages. 586 // The three baltic languages.
587 is_lgc = true;
581 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); 588 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et"));
582 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); 589 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv"));
583 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); 590 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt"));
584 break; 591 break;
585 // TODO(jungshik): Would we be better off mapping Big5 to zh-tw
586 // and GB2312 to zh-cn? Fontconfig has 4 separate orthography
587 // files (zh-{cn,tw,hk,mo}.
588 case NPCharsetChineseBIG5: 592 case NPCharsetChineseBIG5:
593 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw"));
594 break;
589 case NPCharsetGB2312: 595 case NPCharsetGB2312:
590 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh")); 596 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn"));
591 break; 597 break;
592 case NPCharsetEastEurope: 598 case NPCharsetEastEurope:
593 // A scattering of eastern European languages. 599 // A scattering of eastern European languages.
600 is_lgc = true;
594 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); 601 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl"));
595 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); 602 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs"));
596 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); 603 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk"));
597 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu")); 604 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hu"));
598 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); 605 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr"));
599 break; 606 break;
600 case NPCharsetGreek: 607 case NPCharsetGreek:
608 is_lgc = true;
601 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); 609 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el"));
602 break; 610 break;
603 case NPCharsetHangul: 611 case NPCharsetHangul:
604 case NPCharsetJohab: 612 case NPCharsetJohab:
605 // Korean 613 // Korean
606 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); 614 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko"));
607 break; 615 break;
608 case NPCharsetRussian: 616 case NPCharsetRussian:
617 is_lgc = true;
609 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); 618 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru"));
610 break; 619 break;
611 case NPCharsetShiftJIS: 620 case NPCharsetShiftJIS:
612 // Japanese 621 // Japanese
613 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); 622 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja"));
614 break; 623 break;
615 case NPCharsetTurkish: 624 case NPCharsetTurkish:
625 is_lgc = true;
616 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); 626 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr"));
617 break; 627 break;
618 case NPCharsetVietnamese: 628 case NPCharsetVietnamese:
629 is_lgc = true;
619 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); 630 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi"));
620 break; 631 break;
621 case NPCharsetArabic: 632 case NPCharsetArabic:
622 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar")); 633 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ar"));
623 break; 634 break;
624 case NPCharsetHebrew: 635 case NPCharsetHebrew:
625 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he")); 636 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("he"));
626 break; 637 break;
627 case NPCharsetThai: 638 case NPCharsetThai:
628 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th")); 639 FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("th"));
629 break; 640 break;
630 // default: 641 // default:
631 // Don't add any languages in that case that we don't recognise the 642 // Don't add any languages in that case that we don't recognise the
632 // constant. 643 // constant.
633 } 644 }
645 return is_lgc;
634 } 646 }
635 647
636 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, 648 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply,
637 int reply_fd) { 649 int reply_fd) {
638 struct msghdr msg; 650 struct msghdr msg;
639 memset(&msg, 0, sizeof(msg)); 651 memset(&msg, 0, sizeof(msg));
640 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; 652 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()};
641 msg.msg_iov = &iov; 653 msg.msg_iov = &iov;
642 msg.msg_iovlen = 1; 654 msg.msg_iovlen = 1;
643 655
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 RenderSandboxHostLinux::~RenderSandboxHostLinux() { 767 RenderSandboxHostLinux::~RenderSandboxHostLinux() {
756 if (initialized_) { 768 if (initialized_) {
757 if (IGNORE_EINTR(close(renderer_socket_)) < 0) 769 if (IGNORE_EINTR(close(renderer_socket_)) < 0)
758 PLOG(ERROR) << "close"; 770 PLOG(ERROR) << "close";
759 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) 771 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0)
760 PLOG(ERROR) << "close"; 772 PLOG(ERROR) << "close";
761 } 773 }
762 } 774 }
763 775
764 } // namespace content 776 } // namespace content
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