How to use italic method in yandex-tank

Best Python code snippet using yandex-tank

language_specific.py

Source:language_specific.py Github

copy

Full Screen

1#!/usr/bin/env python32# (C) Copyright 2014, Google Inc.3# (C) Copyright 2018, James R Barlow4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7# http://www.apache.org/licenses/LICENSE-2.08# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.13#14# Set some language specific variables. Works in conjunction with15# tesstrain.sh16#17# =============================================================================18# Language specific info19# =============================================================================20import logging21import os22log = logging.getLogger(__name__)23# Array of all valid language codes.24VALID_LANGUAGE_CODES = (25 "afr amh ara asm aze aze_cyrl bel ben bih bod bos bul cat "26 "ceb ces chi_sim chi_tra chr cym cyr_lid dan deu div dzo "27 "ell eng enm epo est eus fas fil fin fra frk frm gle glg "28 "grc guj hat heb hin hrv hun hye iast iku ind isl ita ita_old "29 "jav jav_java jpn kan kat kat_old kaz khm kir kmr kor kur_ara lao lat "30 "lat_lid lav lit mal mar mkd mlt msa mya nep nld nor ori "31 "pan pol por pus ron rus san sin slk slv snd spa spa_old "32 "sqi srp srp_latn swa swe syr tam tel tgk tgl tha tir tur "33 "uig ukr urd uzb uzb_cyrl vie yid gle_uncial "34)35# Codes for which we have webtext but no fonts:36UNUSABLE_LANGUAGE_CODES = ""37FRAKTUR_FONTS = [38 "CaslonishFraxx Medium",39 "Cloister Black, Light",40 "Proclamate Light",41 "UnifrakturMaguntia",42 "Walbaum-Fraktur",43]44# List of fonts to train on45LATIN_FONTS = [46 "Arial Bold",47 "Arial Bold Italic",48 "Arial Italic",49 "Arial",50 "Courier New Bold",51 "Courier New Bold Italic",52 "Courier New Italic",53 "Courier New",54 "Times New Roman, Bold",55 "Times New Roman, Bold Italic",56 "Times New Roman, Italic",57 "Times New Roman,",58 "Georgia Bold",59 "Georgia Italic",60 "Georgia",61 "Georgia Bold Italic",62 "Trebuchet MS Bold",63 "Trebuchet MS Bold Italic",64 "Trebuchet MS Italic",65 "Trebuchet MS",66 "Verdana Bold",67 "Verdana Italic",68 "Verdana",69 "Verdana Bold Italic",70 "URW Bookman L Bold",71 "URW Bookman L Italic",72 "URW Bookman L Bold Italic",73 "Century Schoolbook L Bold",74 "Century Schoolbook L Italic",75 "Century Schoolbook L Bold Italic",76 "Century Schoolbook L Medium",77 "DejaVu Sans Ultra-Light",78]79# List of fonts for printed/neo-Latin ('lat' language code, different from Latin script)80NEOLATIN_FONTS = [81 "GFS Bodoni",82 "GFS Bodoni Bold",83 "GFS Bodoni Italic",84 "GFS Bodoni Bold Italic",85 "GFS Didot",86 "GFS Didot Bold",87 "GFS Didot Italic",88 "GFS Didot Bold Italic",89 "Cardo",90 "Cardo Bold",91 "Cardo Italic",92 "Wyld",93 "Wyld Italic",94 "EB Garamond",95 "EB Garamond Italic",96 "Junicode",97 "Junicode Bold",98 "Junicode Italic",99 "Junicode Bold Italic",100 "IM FELL DW Pica PRO",101 "IM FELL English PRO",102 "IM FELL Double Pica PRO",103 "IM FELL French Canon PRO",104 "IM FELL Great Primer PRO",105 "IM FELL DW Pica PRO Italic",106 "IM FELL English PRO Italic",107 "IM FELL Double Pica PRO Italic",108 "IM FELL French Canon PRO Italic",109 "IM FELL Great Primer PRO Italic",110]111IRISH_UNCIAL_FONTS = [112 "Bunchlo Arsa Dubh GC",113 "Bunchlo Arsa GC",114 "Bunchlo Arsa GC Bold",115 "Bunchlo Dubh GC",116 "Bunchlo GC",117 "Bunchlo GC Bold",118 "Bunchlo Nua GC Bold",119 "Bunchló na Nod GC",120 "Gadelica",121 "Glanchlo Dubh GC",122 "Glanchlo GC",123 "Glanchlo GC Bold",124 "Seanchló Dubh GC",125 "Seanchló GC",126 "Seanchló GC Bold",127 "Seanchló na Nod GC",128 "Seanchló Ársa Dubh GC",129 "Seanchló Ársa GC",130 "Seanchló Ársa GC Bold",131 "Tromchlo Beag GC",132 "Tromchlo Mor GC",133 "Urchlo GC",134 "Urchlo GC Bold",135]136EARLY_LATIN_FONTS = [137 *FRAKTUR_FONTS,138 *LATIN_FONTS,139 # The Wyld font family renders early modern ligatures encoded in the private140 # unicode area.141 "Wyld",142 "Wyld Italic",143 # Fonts that render the Yogh symbol (U+021C, U+021D) found in Old English.144 "GentiumAlt",145]146VIETNAMESE_FONTS = [147 "Arial Unicode MS Bold",148 "Arial Bold Italic",149 "Arial Italic",150 "Arial Unicode MS",151 "FreeMono Bold",152 "Courier New Bold Italic",153 "FreeMono Italic",154 "FreeMono",155 "GentiumAlt Italic",156 "GentiumAlt",157 "Palatino Linotype Bold",158 "Palatino Linotype Bold Italic",159 "Palatino Linotype Italic",160 "Palatino Linotype",161 "Really No 2 LT W2G Light",162 "Really No 2 LT W2G Light Italic",163 "Really No 2 LT W2G Medium",164 "Really No 2 LT W2G Medium Italic",165 "Really No 2 LT W2G Semi-Bold",166 "Really No 2 LT W2G Semi-Bold Italic",167 "Really No 2 LT W2G Ultra-Bold",168 "Really No 2 LT W2G Ultra-Bold Italic",169 "Times New Roman, Bold",170 "Times New Roman, Bold Italic",171 "Times New Roman, Italic",172 "Times New Roman,",173 "Verdana Bold",174 "Verdana Italic",175 "Verdana",176 "Verdana Bold Italic",177 "VL Gothic",178 "VL PGothic",179]180DEVANAGARI_FONTS = [181 "FreeSans",182 "Chandas",183 "Kalimati",184 "Uttara",185 "Lucida Sans",186 "gargi Medium",187 "Lohit Devanagari",188 "Arial Unicode MS Bold",189 "Ascender Uni",190 "Noto Sans Devanagari Bold",191 "Noto Sans Devanagari",192 "Samyak Devanagari Medium",193 "Sarai",194 "Saral LT Bold",195 "Saral LT Light",196 "Nakula",197 "Sahadeva",198 "Samanata",199 "Santipur OT Medium",200]201KANNADA_FONTS = [202 "Kedage Bold",203 "Kedage Italic",204 "Kedage",205 "Kedage Bold Italic",206 "Mallige Bold",207 "Mallige Italic",208 "Mallige",209 "Mallige Bold Italic",210 "Arial Unicode MS",211 "Arial Unicode MS Bold",212 "Ascender Uni",213 "cheluvi Medium",214 "Noto Sans Kannada Bold",215 "Noto Sans Kannada",216 "Lohit Kannada",217 "Tunga",218 "Tunga Bold",219]220TELUGU_FONTS = [221 "Pothana2000",222 "Vemana2000",223 "Lohit Telugu",224 "Arial Unicode MS Bold",225 "Ascender Uni",226 "Dhurjati",227 "Gautami Bold",228 "Gidugu",229 "Gurajada",230 "Lakki Reddy",231 "Mallanna",232 "Mandali",233 "NATS",234 "NTR",235 "Noto Sans Telugu Bold",236 "Noto Sans Telugu",237 "Peddana",238 "Ponnala",239 "Ramabhadra",240 "Ravi Prakash",241 "Sree Krushnadevaraya",242 "Suranna",243 "Suravaram",244 "Tenali Ramakrishna",245 "Gautami",246]247TAMIL_FONTS = [248 "TAMu_Kadambri",249 "TAMu_Kalyani",250 "TAMu_Maduram",251 "TSCu_Paranar",252 "TSCu_Times",253 "TSCu_Paranar Bold",254 "FreeSans",255 "FreeSerif",256 "Lohit Tamil",257 "Arial Unicode MS Bold",258 "Ascender Uni",259 "Droid Sans Tamil Bold",260 "Droid Sans Tamil",261 "Karla Tamil Inclined Bold Italic",262 "Karla Tamil Inclined Italic",263 "Karla Tamil Upright Bold",264 "Karla Tamil Upright",265 "Noto Sans Tamil Bold",266 "Noto Sans Tamil",267 "Noto Sans Tamil UI Bold",268 "Noto Sans Tamil UI",269 "TSCu_Comic Normal",270 "Lohit Tamil Classical",271]272THAI_FONTS = [273 "FreeSerif",274 "FreeSerif Italic",275 "Garuda",276 "Norasi",277 "Lucida Sans Typewriter",278 "Lucida Sans",279 "Garuda Oblique",280 "Norasi Oblique",281 "Norasi Italic",282 "Garuda Bold",283 "Norasi Bold",284 "Lucida Sans Typewriter Bold",285 "Lucida Sans Semi-Bold",286 "Garuda Bold Oblique",287 "Norasi Bold Italic",288 "Norasi Bold Oblique",289 "AnuParp LT Thai",290 "Arial Unicode MS Bold",291 "Arial Unicode MS",292 "Ascender Uni",293 "Loma",294 "Noto Serif Thai Bold",295 "Noto Serif Thai",296 "Purisa Light",297 "Sirichana LT Bold",298 "Sirichana LT",299 "Sukothai LT Bold",300 "Sukothai LT",301 "UtSaHaGumm LT Thai",302 "Tahoma",303]304KOREAN_FONTS = [305 "Arial Unicode MS",306 "Arial Unicode MS Bold",307 "Baekmuk Batang Patched",308 "Baekmuk Batang",309 "Baekmuk Dotum",310 "Baekmuk Gulim",311 "Baekmuk Headline",312]313CHI_SIM_FONTS = [314 "AR PL UKai CN",315 "AR PL UMing Patched Light",316 "Arial Unicode MS",317 "Arial Unicode MS Bold",318 "WenQuanYi Zen Hei Medium",319]320CHI_TRA_FONTS = [321 "AR PL UKai TW",322 "AR PL UMing TW MBE Light",323 "AR PL UKai Patched",324 "AR PL UMing Patched Light",325 "Arial Unicode MS",326 "Arial Unicode MS Bold",327 "WenQuanYi Zen Hei Medium",328]329JPN_FONTS = [330 "TakaoExGothic",331 "TakaoExMincho",332 "TakaoGothic",333 "TakaoMincho",334 "TakaoPGothic",335 "TakaoPMincho",336 "VL Gothic",337 "VL PGothic",338 "Noto Sans Japanese Bold",339 "Noto Sans Japanese Light",340]341RUSSIAN_FONTS = [342 "Arial Bold",343 "Arial Bold Italic",344 "Arial Italic",345 "Arial",346 "Courier New Bold",347 "Courier New Bold Italic",348 "Courier New Italic",349 "Courier New",350 "Times New Roman, Bold",351 "Times New Roman, Bold Italic",352 "Times New Roman, Italic",353 "Times New Roman,",354 "Georgia Bold",355 "Georgia Italic",356 "Georgia",357 "Georgia Bold Italic",358 "Trebuchet MS Bold",359 "Trebuchet MS Bold Italic",360 "Trebuchet MS Italic",361 "Trebuchet MS",362 "Verdana Bold",363 "Verdana Italic",364 "Verdana",365 "Verdana Bold Italic",366 "DejaVu Serif",367 "DejaVu Serif Oblique",368 "DejaVu Serif Bold",369 "DejaVu Serif Bold Oblique",370 "Lucida Bright",371 "FreeSerif Bold",372 "FreeSerif Bold Italic",373 "DejaVu Sans Ultra-Light",374]375GREEK_FONTS = [376 "Arial Unicode MS",377 "Arial Unicode MS Bold",378 "DejaVu Sans Mono",379 "DejaVu Sans Mono Oblique",380 "DejaVu Sans Mono Bold",381 "DejaVu Sans Mono Bold Oblique",382 "DejaVu Serif",383 "DejaVu Serif Semi-Condensed",384 "DejaVu Serif Oblique",385 "DejaVu Serif Bold",386 "DejaVu Serif Bold Oblique",387 "DejaVu Serif Bold Semi-Condensed",388 "FreeSerif Bold",389 "FreeSerif Bold Italic",390 "FreeSerif Italic",391 "FreeSerif",392 "GentiumAlt",393 "GentiumAlt Italic",394 "Linux Biolinum O Bold",395 "Linux Biolinum O",396 "Linux Libertine O Bold",397 "Linux Libertine O",398 "Linux Libertine O Bold Italic",399 "Linux Libertine O Italic",400 "Palatino Linotype Bold",401 "Palatino Linotype Bold Italic",402 "Palatino Linotype Italic",403 "Palatino Linotype",404 "UmePlus P Gothic",405 "VL PGothic",406]407ANCIENT_GREEK_FONTS = [408 "GFS Artemisia",409 "GFS Artemisia Bold",410 "GFS Artemisia Bold Italic",411 "GFS Artemisia Italic",412 "GFS Bodoni",413 "GFS Bodoni Bold",414 "GFS Bodoni Bold Italic",415 "GFS Bodoni Italic",416 "GFS Didot",417 "GFS Didot Bold",418 "GFS Didot Bold Italic",419 "GFS Didot Italic",420 "GFS DidotClassic",421 "GFS Neohellenic",422 "GFS Neohellenic Bold",423 "GFS Neohellenic Bold Italic",424 "GFS Neohellenic Italic",425 "GFS Philostratos",426 "GFS Porson",427 "GFS Pyrsos",428 "GFS Solomos",429]430ARABIC_FONTS = [431 "Arabic Transparent Bold",432 "Arabic Transparent",433 "Arab",434 "Arial Unicode MS Bold",435 "Arial Unicode MS",436 "ASVCodar LT Bold",437 "ASVCodar LT Light",438 "Badiya LT Bold",439 "Badiya LT",440 "Badr LT Bold",441 "Badr LT",442 "Dimnah",443 "Frutiger LT Arabic Bold",444 "Frutiger LT Arabic",445 "Furat",446 "Hassan LT Bold",447 "Hassan LT Light",448 "Jalal LT Bold",449 "Jalal LT Light",450 "Midan Bold",451 "Midan",452 "Mitra LT Bold",453 "Mitra LT Light",454 "Palatino LT Arabic",455 "Palatino Sans Arabic Bold",456 "Palatino Sans Arabic",457 "Simplified Arabic Bold",458 "Simplified Arabic",459 "Times New Roman, Bold",460 "Times New Roman,",461 "Traditional Arabic Bold",462 "Traditional Arabic",463]464HEBREW_FONTS = [465 "Arial Bold",466 "Arial Bold Italic",467 "Arial Italic",468 "Arial",469 "Courier New Bold",470 "Courier New Bold Italic",471 "Courier New Italic",472 "Courier New",473 "Ergo Hebrew Semi-Bold",474 "Ergo Hebrew Semi-Bold Italic",475 "Ergo Hebrew",476 "Ergo Hebrew Italic",477 "Really No 2 LT W2G Light",478 "Really No 2 LT W2G Light Italic",479 "Really No 2 LT W2G Medium",480 "Really No 2 LT W2G Medium Italic",481 "Really No 2 LT W2G Semi-Bold",482 "Really No 2 LT W2G Semi-Bold Italic",483 "Really No 2 LT W2G Ultra-Bold",484 "Really No 2 LT W2G Ultra-Bold Italic",485 "Times New Roman, Bold",486 "Times New Roman, Bold Italic",487 "Times New Roman, Italic",488 "Times New Roman,",489 "Lucida Sans",490 "Tahoma",491]492BENGALI_FONTS = [493 "Bangla Medium",494 "Lohit Bengali",495 "Mukti Narrow",496 "Mukti Narrow Bold",497 "Jamrul Medium Semi-Expanded",498 "Likhan Medium",499 "Arial Unicode MS Bold",500 "Ascender Uni",501 "FreeSans",502 "FreeSans Oblique",503 "FreeSerif",504 "FreeSerif Italic",505 "Noto Sans Bengali Bold",506 "Noto Sans Bengali",507 "Ani",508 "Lohit Assamese",509 "Lohit Bengali",510 "Mitra Mono",511]512KYRGYZ_FONTS = [513 "Arial",514 "Arial Bold",515 "Arial Italic",516 "Arial Bold Italic",517 "Courier New",518 "Courier New Bold",519 "Courier New Italic",520 "Courier New Bold Italic",521 "Times New Roman,",522 "Times New Roman, Bold",523 "Times New Roman, Bold Italic",524 "Times New Roman, Italic",525 "DejaVu Serif",526 "DejaVu Serif Oblique",527 "DejaVu Serif Bold",528 "DejaVu Serif Bold Oblique",529 "Lucida Bright",530 "FreeSerif Bold",531 "FreeSerif Bold Italic",532]533PERSIAN_FONTS = [534 "Amiri Bold Italic",535 "Amiri Bold",536 "Amiri Italic",537 "Amiri",538 "Andale Sans Arabic Farsi",539 "Arial Unicode MS",540 "Arial Unicode MS Bold",541 "Lateef",542 "Lucida Bright",543 "Lucida Sans Oblique",544 "Lucida Sans Semi-Bold",545 "Lucida Sans",546 "Lucida Sans Typewriter Bold",547 "Lucida Sans Typewriter Oblique",548 "Lucida Sans Typewriter",549 "Scheherazade",550 "Tahoma",551 "Times New Roman,",552 "Times New Roman, Bold",553 "Times New Roman, Bold Italic",554 "Times New Roman, Italic",555 "Yakout Linotype Bold",556 "Yakout Linotype",557]558AMHARIC_FONTS = [559 "Abyssinica SIL",560 "Droid Sans Ethiopic Bold",561 "Droid Sans Ethiopic",562 "FreeSerif",563 "Noto Sans Ethiopic Bold",564 "Noto Sans Ethiopic",565]566ARMENIAN_FONTS = [567 "Arial Unicode MS",568 "Arial Unicode MS Bold",569 "Ascender Uni",570 "FreeMono",571 "FreeMono Italic",572 "FreeSans",573 "FreeSans Bold",574 "FreeSans Oblique",575]576BURMESE_FONTS = [577 "Myanmar Sans Pro",578 "Noto Sans Myanmar Bold",579 "Noto Sans Myanmar",580 "Padauk Bold",581 "Padauk",582 "TharLon",583]584JAVANESE_FONTS = ["Prada"]585NORTH_AMERICAN_ABORIGINAL_FONTS = [586 "Aboriginal Sans",587 "Aboriginal Sans Bold Italic",588 "Aboriginal Sans Italic",589 "Aboriginal Sans Bold",590 "Aboriginal Serif Bold",591 "Aboriginal Serif Bold Italic",592 "Aboriginal Serif Italic",593 "Aboriginal Serif",594]595GEORGIAN_FONTS = [596 "Arial Unicode MS Bold",597 "Arial Unicode MS",598 "BPG Algeti GPL\&GNU",599 "BPG Chveulebrivi GPL\&GNU",600 "BPG Courier GPL\&GNU",601 "BPG Courier S GPL\&GNU",602 "BPG DejaVu Sans 2011 GNU-GPL",603 "BPG Elite GPL\&GNU",604 "BPG Excelsior GPL\&GNU",605 "BPG Glaho GPL\&GNU",606 "BPG Gorda GPL\&GNU",607 "BPG Ingiri GPL\&GNU",608 "BPG Mrgvlovani Caps GNU\&GPL",609 "BPG Mrgvlovani GPL\&GNU",610 "BPG Nateli Caps GPL\&GNU Light",611 "BPG Nateli Condenced GPL\&GNU Light",612 "BPG Nateli GPL\&GNU Light",613 "BPG Nino Medium Cond GPL\&GNU",614 "BPG Nino Medium GPL\&GNU Medium",615 "BPG Sans GPL\&GNU",616 "BPG Sans Medium GPL\&GNU",617 "BPG Sans Modern GPL\&GNU",618 "BPG Sans Regular GPL\&GNU",619 "BPG Serif GPL\&GNU",620 "BPG Serif Modern GPL\&GNU",621 "FreeMono",622 "FreeMono Bold Italic",623 "FreeSans",624 "FreeSerif",625 "FreeSerif Bold",626 "FreeSerif Bold Italic",627 "FreeSerif Italic",628]629OLD_GEORGIAN_FONTS = [630 "Arial Unicode MS Bold",631 "Arial Unicode MS",632 "BPG Algeti GPL\&GNU",633 "BPG Courier S GPL\&GNU",634 "BPG DejaVu Sans 2011 GNU-GPL",635 "BPG Elite GPL\&GNU",636 "BPG Excelsior GPL\&GNU",637 "BPG Glaho GPL\&GNU",638 "BPG Ingiri GPL\&GNU",639 "BPG Mrgvlovani Caps GNU\&GPL",640 "BPG Mrgvlovani GPL\&GNU",641 "BPG Nateli Caps GPL\&GNU Light",642 "BPG Nateli Condenced GPL\&GNU Light",643 "BPG Nateli GPL\&GNU Light",644 "BPG Nino Medium Cond GPL\&GNU",645 "BPG Nino Medium GPL\&GNU Medium",646 "BPG Sans GPL\&GNU",647 "BPG Sans Medium GPL\&GNU",648 "BPG Sans Modern GPL\&GNU",649 "BPG Sans Regular GPL\&GNU",650 "BPG Serif GPL\&GNU",651 "BPG Serif Modern GPL\&GNU",652 "FreeSans",653 "FreeSerif",654 "FreeSerif Bold",655 "FreeSerif Bold Italic",656 "FreeSerif Italic",657]658KHMER_FONTS = [659 "Khmer OS",660 "Khmer OS System",661 "Khmer OS Battambang",662 "Khmer OS Bokor",663 "Khmer OS Content",664 "Khmer OS Fasthand",665 "Khmer OS Freehand",666 "Khmer OS Metal Chrieng",667 "Khmer OS Muol Light",668 "Khmer OS Muol Pali",669 "Khmer OS Muol",670 "Khmer OS Siemreap",671 "Noto Sans Bold",672 "Noto Sans",673 "Noto Serif Khmer Bold",674 "Noto Serif Khmer Light",675]676KURDISH_FONTS = [677 "Amiri Bold Italic",678 "Amiri Bold",679 "Amiri Italic",680 "Amiri",681 "Arial Unicode MS",682 "Arial Unicode MS Bold",683 "Lateef",684 "Lucida Bright",685 "Lucida Sans Oblique",686 "Lucida Sans Semi-Bold",687 "Lucida Sans",688 "Lucida Sans Typewriter Bold",689 "Lucida Sans Typewriter Oblique",690 "Lucida Sans Typewriter",691 "Scheherazade",692 "Tahoma",693 "Times New Roman,",694 "Times New Roman, Bold",695 "Times New Roman, Bold Italic",696 "Times New Roman, Italic",697 "Unikurd Web",698 "Yakout Linotype Bold",699 "Yakout Linotype",700]701LAOTHIAN_FONTS = [702 "Phetsarath OT",703 "Arial Unicode MS",704 "Arial Unicode MS Bold",705 "Ascender Uni",706 "Dhyana Bold",707 "Dhyana",708 "Lao Muang Don",709 "Lao Muang Khong",710 "Lao Sans Pro",711 "Noto Sans Lao Bold",712 "Noto Sans Lao",713 "Noto Sans Lao UI Bold",714 "Noto Sans Lao UI",715 "Noto Serif Lao Bold",716 "Noto Serif Lao",717 "Phetsarath Bold",718 "Phetsarath",719 "Souliyo Unicode",720]721GUJARATI_FONTS = [722 "Lohit Gujarati",723 "Rekha Medium",724 "Samyak Gujarati Medium",725 "aakar Medium",726 "padmaa Bold",727 "padmaa Medium",728 "Arial Unicode MS",729 "Arial Unicode MS Bold",730 "Ascender Uni",731 "FreeSans",732 "Noto Sans Gujarati Bold",733 "Noto Sans Gujarati",734 "Shruti",735 "Shruti Bold",736]737MALAYALAM_FONTS = [738 "AnjaliOldLipi",739 "Arial Unicode MS",740 "Arial Unicode MS Bold",741 "Ascender Uni",742 "Dyuthi",743 "FreeSerif",744 "Kalyani",745 "Kartika",746 "Kartika Bold",747 "Lohit Malayalam",748 "Meera",749 "Noto Sans Malayalam Bold",750 "Noto Sans Malayalam",751 "Rachana",752 "Rachana_w01",753 "RaghuMalayalam",754 "suruma",755]756ORIYA_FONTS = [757 "Arial Unicode MS",758 "Arial Unicode MS Bold",759 "Ascender Uni",760 "ori1Uni Medium",761 "Samyak Oriya Medium",762 "Lohit Oriya",763]764PUNJABI_FONTS = [765 "Arial Unicode MS",766 "Arial Unicode MS Bold",767 "Ascender Uni",768 "Saab",769 "Lohit Punjabi",770 "Noto Sans Gurmukhi",771 "Noto Sans Gurmukhi Bold",772 "FreeSans",773 "FreeSans Bold",774 "FreeSerif",775]776SINHALA_FONTS = [777 "Noto Sans Sinhala Bold",778 "Noto Sans Sinhala",779 "OCRUnicode",780 "Yagpo",781 "LKLUG",782 "FreeSerif",783]784SYRIAC_FONTS = [785 "East Syriac Adiabene",786 "East Syriac Ctesiphon",787 "Estrangelo Antioch",788 "Estrangelo Edessa",789 "Estrangelo Midyat",790 "Estrangelo Nisibin",791 "Estrangelo Quenneshrin",792 "Estrangelo Talada",793 "Estrangelo TurAbdin",794 "Serto Batnan Bold",795 "Serto Batnan",796 "Serto Jerusalem Bold",797 "Serto Jerusalem Italic",798 "Serto Jerusalem",799 "Serto Kharput",800 "Serto Malankara",801 "Serto Mardin Bold",802 "Serto Mardin",803 "Serto Urhoy Bold",804 "Serto Urhoy",805 "FreeSans",806]807THAANA_FONTS = ["FreeSerif"]808TIBETAN_FONTS = [809 "Arial Unicode MS",810 "Arial Unicode MS Bold",811 "Ascender Uni",812 "DDC Uchen",813 "Jomolhari",814 "Kailasa",815 "Kokonor",816 "Tibetan Machine Uni",817 "TibetanTsugRing",818 "Yagpo",819]820# The following fonts will be rendered vertically in phase I.821VERTICAL_FONTS = [822 "TakaoExGothic",823 "TakaoExMincho",824 "AR PL UKai Patched",825 "AR PL UMing Patched Light",826 "Baekmuk Batang Patched",827]828FLAGS_webtext_prefix = os.environ.get("FLAGS_webtext_prefix", "")829# Set language-specific values for several global variables, including830# ${TEXT_CORPUS}831# holds the text corpus file for the language, used in phase F832# ${FONTS[@]}833# holds a sequence of applicable fonts for the language, used in834# phase F & I. only set if not already set, i.e. from command line835# ${TRAINING_DATA_ARGUMENTS}836# non-default arguments to the training_data program used in phase T837# ${FILTER_ARGUMENTS}[ -]838# character-code-specific filtering to distinguish between scripts839# (eg. CJK) used by filter_borbidden_characters in phase F840# ${WORDLIST2DAWG_ARGUMENTS}841# specify fixed length dawg generation for non-space-delimited lang842# TODO(dsl): We can refactor these into functions that assign FONTS,843# TEXT_CORPUS, etc. separately.844def set_lang_specific_parameters(ctx, lang):845 # The default text location is now given directly from the language code.846 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/{lang}.corpus.txt"847 FILTER_ARGUMENTS = []848 WORDLIST2DAWG_ARGUMENTS = ""849 # These dawg factors represent the fraction of the corpus not covered by the850 # dawg, and seem like reasonable defaults, but the optimal value is likely851 # to be highly corpus-dependent, as well as somewhat language-dependent.852 # Number dawg factor is the fraction of all numeric strings that are not853 # covered, which is why it is higher relative to the others.854 PUNC_DAWG_FACTOR = None855 NUMBER_DAWG_FACTOR = 0.125856 WORD_DAWG_FACTOR = 0.05857 BIGRAM_DAWG_FACTOR = 0.015858 TRAINING_DATA_ARGUMENTS = []859 FRAGMENTS_DISABLED = "y"860 RUN_SHAPE_CLUSTERING = False861 AMBIGS_FILTER_DENOMINATOR = "100000"862 LEADING = 32863 MEAN_COUNT = 40 # Default for latin script.864 # Language to mix with the language for maximum accuracy. Defaults to eng.865 # If no language is good, set to the base language.866 MIX_LANG = "eng"867 FONTS = ctx.fonts868 TEXT2IMAGE_EXTRA_ARGS = []869 EXPOSURES = []870 GENERATE_WORD_BIGRAMS = None871 WORD_DAWG_SIZE = None872 # Latin languages.873 if lang == "enm":874 TEXT2IMAGE_EXTRA_ARGS += ["--ligatures"] # Add ligatures when supported875 if not FONTS:876 FONTS = EARLY_LATIN_FONTS877 elif lang == "frm":878 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/fra.corpus.txt"879 # Make long-s substitutions for Middle French text880 FILTER_ARGUMENTS += ["--make_early_language_variant=fra"]881 TEXT2IMAGE_EXTRA_ARGS += ["--ligatures"] # Add ligatures when supported.882 if not FONTS:883 FONTS = EARLY_LATIN_FONTS884 elif lang == "frk":885 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/deu.corpus.txt"886 if not FONTS:887 FONTS = FRAKTUR_FONTS888 elif lang == "ita_old":889 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/ita.corpus.txt"890 # Make long-s substitutions for Early Italian text891 FILTER_ARGUMENTS += ["--make_early_language_variant=ita"]892 TEXT2IMAGE_EXTRA_ARGS += ["--ligatures"] # Add ligatures when supported.893 if not FONTS:894 FONTS = EARLY_LATIN_FONTS895 elif lang == "lat":896 if not EXPOSURES:897 EXPOSURES = "-3 -2 -1 0 1 2 3".split()898 if not FONTS:899 FONTS = NEOLATIN_FONTS900 elif lang == "spa_old":901 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/spa.corpus.txt"902 # Make long-s substitutions for Early Spanish text903 FILTER_ARGUMENTS += ["--make_early_language_variant=spa"]904 TEXT2IMAGE_EXTRA_ARGS += ["--ligatures"] # Add ligatures when supported.905 if not FONTS:906 FONTS = EARLY_LATIN_FONTS907 elif lang == "srp_latn":908 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/srp.corpus.txt"909 elif lang == "vie":910 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]911 if not FONTS:912 FONTS = VIETNAMESE_FONTS913 # Highly inflective languages get a bigger dawg size.914 # TODO(rays) Add more here!915 elif lang == "hun":916 WORD_DAWG_SIZE = 1_000_000917 elif lang == "pol":918 WORD_DAWG_SIZE = 1_000_000919 # Latin with default treatment.920 elif lang == "afr":921 pass922 elif lang == "aze":923 pass924 elif lang == "bos":925 pass926 elif lang == "cat":927 pass928 elif lang == "ceb":929 pass930 elif lang == "ces":931 PUNC_DAWG_FACTOR = 0.004932 elif lang == "cym":933 pass934 elif lang == "dan":935 pass936 elif lang == "deu":937 WORD_DAWG_FACTOR = 0.125938 elif lang == "eng":939 WORD_DAWG_FACTOR = 0.03940 elif lang == "epo":941 pass942 elif lang == "est":943 pass944 elif lang == "eus":945 pass946 elif lang == "fil":947 pass948 elif lang == "fin":949 pass950 elif lang == "fra":951 WORD_DAWG_FACTOR = 0.08952 elif lang == "gle":953 pass954 elif lang == "gle_uncial":955 if not FONTS:956 FONTS = IRISH_UNCIAL_FONTS957 elif lang == "glg":958 pass959 elif lang == "hat":960 pass961 elif lang == "hrv":962 pass963 elif lang == "iast":964 pass965 elif lang == "ind":966 pass967 elif lang == "isl":968 pass969 elif lang == "ita":970 pass971 elif lang == "jav":972 pass973 elif lang == "lav":974 pass975 elif lang == "lit":976 pass977 elif lang == "mlt":978 pass979 elif lang == "msa":980 pass981 elif lang == "nld":982 WORD_DAWG_FACTOR = 0.02983 elif lang == "nor":984 pass985 elif lang == "por":986 pass987 elif lang == "ron":988 pass989 elif lang == "slk":990 pass991 elif lang == "slv":992 pass993 elif lang == "spa":994 pass995 elif lang == "sqi":996 pass997 elif lang == "swa":998 pass999 elif lang == "swe":1000 pass1001 elif lang == "tgl":1002 pass1003 elif lang == "tur":1004 pass1005 elif lang == "uzb":1006 pass1007 elif lang == "zlm":1008 pass1009 # Special code for performing language-id that is trained on1010 # EFIGS+Latin+Vietnamese text with regular + fraktur fonts.1011 elif lang == "lat_lid":1012 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/lat_lid.corpus.txt"1013 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1014 GENERATE_WORD_BIGRAMS = 01015 # Strip unrenderable words as not all fonts will render the extended1016 # latin symbols found in Vietnamese text.1017 WORD_DAWG_SIZE = 1_000_0001018 if not FONTS:1019 FONTS = EARLY_LATIN_FONTS1020 # Cyrillic script-based languages. It is bad to mix Latin with Cyrillic.1021 elif lang == "rus":1022 if not FONTS:1023 FONTS = RUSSIAN_FONTS1024 MIX_LANG = "rus"1025 NUMBER_DAWG_FACTOR = 0.051026 WORD_DAWG_SIZE = 1_000_0001027 elif lang in (1028 "aze_cyrl",1029 "bel",1030 "bul",1031 "kaz",1032 "mkd",1033 "srp",1034 "tgk",1035 "ukr",1036 "uzb_cyrl",1037 ):1038 MIX_LANG = f"{lang}"1039 if not FONTS:1040 FONTS = RUSSIAN_FONTS1041 # Special code for performing Cyrillic language-id that is trained on1042 # Russian, Serbian, Ukrainian, Belarusian, Macedonian, Tajik and Mongolian1043 # text with the list of Russian fonts.1044 elif lang == "cyr_lid":1045 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/cyr_lid.corpus.txt"1046 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1047 GENERATE_WORD_BIGRAMS = 01048 WORD_DAWG_SIZE = 1_000_0001049 if not FONTS:1050 FONTS = RUSSIAN_FONTS1051 # South Asian scripts mostly have a lot of different graphemes, so trim1052 # down the MEAN_COUNT so as not to get a huge amount of text.1053 elif lang in ("asm", "ben"):1054 MEAN_COUNT = 151055 WORD_DAWG_FACTOR = 0.151056 if not FONTS:1057 FONTS = BENGALI_FONTS1058 elif lang in ("bih", "hin", "mar", "nep", "san"):1059 MEAN_COUNT = 151060 WORD_DAWG_FACTOR = 0.151061 if not FONTS:1062 FONTS = DEVANAGARI_FONTS1063 elif lang == "bod":1064 MEAN_COUNT = 151065 WORD_DAWG_FACTOR = 0.151066 if not FONTS:1067 FONTS = TIBETAN_FONTS1068 elif lang == "dzo":1069 WORD_DAWG_FACTOR = 0.011070 if not FONTS:1071 FONTS = TIBETAN_FONTS1072 elif lang == "guj":1073 MEAN_COUNT = 151074 WORD_DAWG_FACTOR = 0.151075 if not FONTS:1076 FONTS = GUJARATI_FONTS1077 elif lang == "kan":1078 MEAN_COUNT = 151079 WORD_DAWG_FACTOR = 0.151080 TRAINING_DATA_ARGUMENTS += ["--no_newline_in_output"]1081 TEXT2IMAGE_EXTRA_ARGS += ["--char_spacing=0.5"]1082 if not FONTS:1083 FONTS = KANNADA_FONTS1084 elif lang == "mal":1085 MEAN_COUNT = 151086 WORD_DAWG_FACTOR = 0.151087 TRAINING_DATA_ARGUMENTS += ["--no_newline_in_output"]1088 TEXT2IMAGE_EXTRA_ARGS += ["--char_spacing=0.5"]1089 if not FONTS:1090 FONTS = MALAYALAM_FONTS1091 elif lang == "ori":1092 WORD_DAWG_FACTOR = 0.011093 if not FONTS:1094 FONTS = ORIYA_FONTS1095 elif lang == "pan":1096 MEAN_COUNT = 151097 WORD_DAWG_FACTOR = 0.011098 if not FONTS:1099 FONTS = PUNJABI_FONTS1100 elif lang == "sin":1101 MEAN_COUNT = 151102 WORD_DAWG_FACTOR = 0.011103 if not FONTS:1104 FONTS = SINHALA_FONTS1105 elif lang == "tam":1106 MEAN_COUNT = 301107 WORD_DAWG_FACTOR = 0.151108 TRAINING_DATA_ARGUMENTS += ["--no_newline_in_output"]1109 TEXT2IMAGE_EXTRA_ARGS += ["--char_spacing=0.5"]1110 if not FONTS:1111 FONTS = TAMIL_FONTS1112 elif lang == "tel":1113 MEAN_COUNT = 151114 WORD_DAWG_FACTOR = 0.151115 TRAINING_DATA_ARGUMENTS += ["--no_newline_in_output"]1116 TEXT2IMAGE_EXTRA_ARGS += ["--char_spacing=0.5"]1117 if not FONTS:1118 FONTS = TELUGU_FONTS1119 # SouthEast Asian scripts.1120 elif lang == "jav_java":1121 MEAN_COUNT = 151122 WORD_DAWG_FACTOR = 0.151123 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1124 if not FONTS:1125 FONTS = JAVANESE_FONTS1126 elif lang == "khm":1127 MEAN_COUNT = 151128 WORD_DAWG_FACTOR = 0.151129 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1130 if not FONTS:1131 FONTS = KHMER_FONTS1132 elif lang == "lao":1133 MEAN_COUNT = 151134 WORD_DAWG_FACTOR = 0.151135 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1136 if not FONTS:1137 FONTS = LAOTHIAN_FONTS1138 elif lang == "mya":1139 MEAN_COUNT = 121140 WORD_DAWG_FACTOR = 0.151141 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1142 if not FONTS:1143 FONTS = BURMESE_FONTS1144 elif lang == "tha":1145 MEAN_COUNT = 301146 WORD_DAWG_FACTOR = 0.011147 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1148 FILTER_ARGUMENTS += ["--segmenter_lang=tha"]1149 TRAINING_DATA_ARGUMENTS += ["--no_space_in_output", "--desired_bigrams="]1150 AMBIGS_FILTER_DENOMINATOR = "1000"1151 LEADING = 481152 if not FONTS:1153 FONTS = THAI_FONTS1154 # CJK1155 elif lang == "chi_sim":1156 MEAN_COUNT = 151157 PUNC_DAWG_FACTOR = 0.0151158 WORD_DAWG_FACTOR = 0.0151159 GENERATE_WORD_BIGRAMS = 01160 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1161 TRAINING_DATA_ARGUMENTS += ["--no_space_in_output", "--desired_bigrams="]1162 FILTER_ARGUMENTS += ["--charset_filter=chi_sim", "--segmenter_lang=chi_sim"]1163 if not FONTS:1164 FONTS = CHI_SIM_FONTS1165 elif lang == "chi_tra":1166 MEAN_COUNT = 151167 WORD_DAWG_FACTOR = 0.0151168 GENERATE_WORD_BIGRAMS = 01169 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1170 TRAINING_DATA_ARGUMENTS += ["--no_space_in_output", "--desired_bigrams="]1171 FILTER_ARGUMENTS += ["--charset_filter=chi_tr", "--segmenter_lang=chi_tra"]1172 if not FONTS:1173 FONTS = CHI_TRA_FONTS1174 elif lang == "jpn":1175 MEAN_COUNT = 151176 WORD_DAWG_FACTOR = 0.0151177 GENERATE_WORD_BIGRAMS = 01178 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1179 TRAINING_DATA_ARGUMENTS += ["--no_space_in_output", "--desired_bigrams="]1180 FILTER_ARGUMENTS += ["--charset_filter=jpn", "--segmenter_lang=jpn"]1181 if not FONTS:1182 FONTS = JPN_FONTS1183 elif lang == "kor":1184 MEAN_COUNT = 201185 WORD_DAWG_FACTOR = 0.0151186 NUMBER_DAWG_FACTOR = 0.051187 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=10000"]1188 TRAINING_DATA_ARGUMENTS += ["--desired_bigrams="]1189 GENERATE_WORD_BIGRAMS = 01190 FILTER_ARGUMENTS += ["--charset_filter=kor", "--segmenter_lang=kor"]1191 if not FONTS:1192 FONTS = KOREAN_FONTS1193 # Middle-Eastern scripts.1194 elif lang == "ara":1195 if not FONTS:1196 FONTS = ARABIC_FONTS1197 elif lang == "div":1198 if not FONTS:1199 FONTS = THAANA_FONTS1200 elif lang in ("fas", "pus", "snd", "uig", "urd"):1201 if not FONTS:1202 FONTS = PERSIAN_FONTS1203 elif lang in ("heb", "yid"):1204 NUMBER_DAWG_FACTOR = 0.051205 WORD_DAWG_FACTOR = 0.081206 if not FONTS:1207 FONTS = HEBREW_FONTS1208 elif lang == "syr":1209 if not FONTS:1210 FONTS = SYRIAC_FONTS1211 # Other scripts.1212 elif lang in ("amh", "tir"):1213 if not FONTS:1214 FONTS = AMHARIC_FONTS1215 elif lang == "chr":1216 if not FONTS:1217 FONTS = [*NORTH_AMERICAN_ABORIGINAL_FONTS, "Noto Sans Cherokee"]1218 elif lang == "ell":1219 NUMBER_DAWG_FACTOR = 0.051220 WORD_DAWG_FACTOR = 0.081221 if not FONTS:1222 FONTS = GREEK_FONTS1223 elif lang == "grc":1224 if not EXPOSURES:1225 EXPOSURES = "-3 -2 -1 0 1 2 3".split()1226 if not FONTS:1227 FONTS = ANCIENT_GREEK_FONTS1228 elif lang == "hye":1229 if not FONTS:1230 FONTS = ARMENIAN_FONTS1231 elif lang == "iku":1232 if not FONTS:1233 FONTS = NORTH_AMERICAN_ABORIGINAL_FONTS1234 elif lang == "kat":1235 if not FONTS:1236 FONTS = GEORGIAN_FONTS1237 elif lang == "kat_old":1238 TEXT_CORPUS = f"{FLAGS_webtext_prefix}/kat.corpus.txt"1239 if not FONTS:1240 FONTS = OLD_GEORGIAN_FONTS1241 elif lang == "kir":1242 if not FONTS:1243 FONTS = KYRGYZ_FONTS1244 TRAINING_DATA_ARGUMENTS += ["--infrequent_ratio=100"]1245 elif lang == "kmr":1246 if not FONTS:1247 FONTS = LATIN_FONTS1248 elif lang == "kur_ara":1249 if not FONTS:1250 FONTS = KURDISH_FONTS1251 else:1252 raise ValueError(f"Error: {lang} is not a valid language code")1253 FLAGS_mean_count = int(os.environ.get("FLAGS_mean_count", -1))1254 if FLAGS_mean_count > 0:1255 TRAINING_DATA_ARGUMENTS += [f"--mean_count={FLAGS_mean_count}"]1256 elif not MEAN_COUNT:1257 TRAINING_DATA_ARGUMENTS += [f"--mean_count={MEAN_COUNT}"]1258 # Default to Latin fonts if none have been set1259 if not FONTS:1260 FONTS = LATIN_FONTS1261 # Default to 0 exposure if it hasn't been set1262 if not EXPOSURES:1263 EXPOSURES = [0]1264 # Set right-to-left and normalization mode.1265 if lang in (1266 "ara",1267 "div",1268 "fas",1269 "pus",1270 "snd",1271 "syr",1272 "uig",1273 "urd",1274 "kur_ara",1275 "heb",1276 "yid",1277 ):1278 LANG_IS_RTL = True1279 NORM_MODE = 21280 elif lang in (1281 "asm",1282 "ben",1283 "bih",1284 "hin",1285 "mar",1286 "nep",1287 "guj",1288 "kan",1289 "mal",1290 "tam",1291 "tel",1292 "pan",1293 "dzo",1294 "sin",1295 "san",1296 "bod",1297 "ori",1298 "khm",1299 "mya",1300 "tha",1301 "lao",1302 "jav ",1303 "jav_java",1304 ):1305 LANG_IS_RTL = False1306 NORM_MODE = 21307 else:1308 LANG_IS_RTL = False1309 NORM_MODE = 11310 vars_to_transfer = {1311 'ambigs_filter_denominator': AMBIGS_FILTER_DENOMINATOR,1312 'bigram_dawg_factor': BIGRAM_DAWG_FACTOR,1313 'exposures': EXPOSURES,1314 'filter_arguments': FILTER_ARGUMENTS,1315 'fonts': FONTS,1316 'fragments_disabled': FRAGMENTS_DISABLED,1317 'generate_word_bigrams': GENERATE_WORD_BIGRAMS,1318 'lang_is_rtl': LANG_IS_RTL,1319 'leading': LEADING,1320 'mean_count': MEAN_COUNT,1321 'mix_lang': MIX_LANG,1322 'norm_mode': NORM_MODE,1323 'number_dawg_factor': NUMBER_DAWG_FACTOR,1324 'punc_dawg_factor': PUNC_DAWG_FACTOR,1325 'run_shape_clustering': RUN_SHAPE_CLUSTERING,1326 'text2image_extra_args': TEXT2IMAGE_EXTRA_ARGS,1327 'text_corpus': TEXT_CORPUS,1328 'training_data_arguments': TRAINING_DATA_ARGUMENTS,1329 'word_dawg_factor': WORD_DAWG_FACTOR,1330 'word_dawg_size': WORD_DAWG_SIZE,1331 'wordlist2dawg_arguments': WORDLIST2DAWG_ARGUMENTS,1332 }1333 for attr, value in vars_to_transfer.items():1334 if hasattr(ctx, attr):1335 if getattr(ctx, attr) != value:1336 log.debug(f"{attr} = {value} (was {getattr(ctx, attr)})")1337 setattr(ctx, attr, value)1338 else:1339 log.debug(f"{attr} = {value} (set on cmdline)")1340 else:1341 log.debug(f"{attr} = {value}")1342 setattr(ctx, attr, value)1343 return ctx1344# =============================================================================1345# END of Language specific info...

Full Screen

Full Screen

ItalicBowtie.py

Source:ItalicBowtie.py Github

copy

Full Screen

1#!/usr/bin/env python32import math3from fontTools.misc.transform import Identity4from vanilla import FloatingWindow, TextBox, EditText5from vanilla import Button, RadioGroup, CheckBox6from mojo.roboFont import CurrentFont, AllFonts, CurrentGlyph7from mojo.UI import CurrentGlyphWindow8from mojo.extensions import getExtensionDefault, setExtensionDefault9from mojo.subscriber import WindowController, Subscriber, registerGlyphEditorSubscriber10######################11# ITALIC OFFSET MATH #12######################13def calcItalicOffset(yoffset, italicAngle):14 '''15 Given a y offset and an italic angle, calculate the x offset.16 '''17 from math import radians, tan18 ritalicAngle = radians(italicAngle)19 xoffset = int(round(tan(ritalicAngle) * yoffset))20 return xoffset*-121def calcItalicRise(xoffset, italicAngle):22 '''23 Given a x offset and an italic angle, calculate the y offset.24 '''25 from math import radians, tan26 if italicAngle == 0:27 return 028 ritalicAngle = radians(italicAngle)29 yoffset = int(round( float(xoffset) / tan(ritalicAngle) ))30 return yoffset31def calcItalicCoordinates(coords, italicAngle):32 """33 Given (x, y) coords and an italic angle, get new coordinates accounting for italic offset.34 """35 x, y = coords36 x += calcItalicOffset(y, italicAngle)37 return x, y38################39# ITALIC TOOLS #40################41def calcItalicSlantOffset(italicAngle=0, crossHeight=0):42 """43 Get italic slant offset.44 """45 return calcItalicOffset(-crossHeight, italicAngle)46def calcCrossHeight(italicAngle=0, italicSlantOffset=0):47 return calcItalicRise(italicSlantOffset, italicAngle)48def makeReferenceLayer(source, italicAngle, backgroundName='com.fontbureau.italicReference'):49 """50 Store a vertically skewed copy in the mask.51 """52 italicSlant = abs(italicAngle)53 g = source.getLayer(backgroundName)54 g.decompose()55 source.copyToLayer(backgroundName)56 # use for vertical offset later57 top1 = g.box[3]58 bottom1 = g.box[1]59 height1 = top1 + abs(bottom1)60 # vertical skew61 m = Identity62 dx = 063 dy = italicSlant/2.0 # half the italic angle64 x = math.radians(dx)65 y = math.radians(dy)66 m = m.skew(x, -y)67 g.transform(m)68 top2 = g.box[3]69 bottom2 = g.box[1]70 height2 = top2 + abs(bottom2)71 dif = (height1-height2) / 272 yoffset = (abs(bottom2)-abs(bottom1)) + dif73 g.move((0, yoffset))74def italicize(glyph,75 italicAngle=None,76 offset=0,77 doContours = True,78 doAnchors = True,79 doGuides = True,80 doComponents = True,81 doImage = True,82 shouldMakeReferenceLayer=True,83 DEBUG=False):84 """85 Oblique a glyph using cap height and italic angle.86 """87 with glyph.undo("italicBowtie"):88 xoffset = offset89 # skew the glyph horizontally90 glyph.skew(-italicAngle, (0, 0))91 if doContours:92 for c in glyph.contours:93 c.move((xoffset, 0))94 if DEBUG:95 print(f'\t\t\t {c}')96 # anchors97 if doAnchors:98 for anchor in glyph.anchors:99 anchor.move((xoffset, 0))100 if DEBUG:101 print(f'\t\t\t {anchor}')102 # guides103 if doGuides:104 for guide in glyph.guides:105 guide.x += xoffset106 if DEBUG:107 print(f'\t\t\t {guide} {guide.x}')108 # image109 if doImage:110 if glyph.image:111 glyph.image.move((xoffset, 0))112 if DEBUG:113 print(f'\t\t\t {glyph.image}')114 if doComponents:115 for c in glyph.components:116 cxoffset = calcItalicOffset(c.offset[1], italicAngle)117 c.offset = (c.offset[0]-cxoffset, c.offset[1])118 if not glyph.components and shouldMakeReferenceLayer:119 makeReferenceLayer(glyph, italicAngle)120 glyph.markColor = (0, .1, 1, .2)121############122# THE TOOL #123############124class ItalicBowtie(Subscriber, WindowController):125 DEFAULTKEY = 'com.fontbureau.italicBowtie'126 DEFAULTKEY_REFERENCE = DEFAULTKEY + '.drawReferenceGlyph'127 italicSlantOffsetKey = 'com.typemytype.robofont.italicSlantOffset'128 debug = True129 def build(self):130 glyphEditor = self.getGlyphEditor()131 self.container = glyphEditor.extensionContainer(132 identifier="com.roboFont.ItalicBowtie.background",133 location="background",134 clear=True)135 self.crossHeightLayer = self.container.appendLineSublayer(136 strokeWidth=1,137 strokeColor=(.2, .1, .5, .5),138 strokeDash=(2,)139 )140 fillColor = (.2, .1, .5, .05)141 strokeColor = (.2, .1, .5, .5)142 strokeWidth = 0.5143 self.leftBowtieLayer = self.container.appendPathSublayer(144 fillColor=fillColor,145 strokeColor=strokeColor,146 strokeWidth=strokeWidth147 )148 self.rightBowtieLayer = self.container.appendPathSublayer(149 fillColor=fillColor,150 strokeColor=strokeColor,151 strokeWidth=strokeWidth152 )153 self.w = FloatingWindow((325, 250), "Italic Bowtie")154 self.populateWindow()155 def started(self):156 self.w.open()157 def destroy(self):158 self.container.clearSublayers()159 def glyphEditorGlyphDidChange(self, info):160 self.updateBowtie()161 def glyphEditorDidSetGlyph(self, info):162 self.updateBowtie()163 def populateWindow(self):164 y = 10165 x = 10166 self.w.italicAngleLabel = TextBox((x, y+4, 100, 22), 'Italic Angle', sizeStyle="small")167 x += 100168 self.w.italicAngle = EditText((x, y, 40, 22), '', sizeStyle="small", callback=self.calcItalicCallback)169 y += 30170 x = 10171 self.w.crossHeightLabel = TextBox((x, y+4, 95, 22), 'Cross Height', sizeStyle="small")172 x += 100173 self.w.crossHeight = EditText((x, y, 40, 22), '', sizeStyle="small", callback=self.calcItalicCallback)174 x += 50175 self.w.crossHeightSetUC = Button((x, y, 65, 22), 'Mid UC', sizeStyle="small", callback=self.calcItalicCallback)176 x += 75177 self.w.crossHeightSetLC = Button((x, y, 65, 22), 'Mid LC', sizeStyle="small", callback=self.calcItalicCallback)178 y += 30179 x = 10180 self.w.italicSlantOffsetLabel = TextBox((x, y+4, 100, 22), 'Italic Slant Offset', sizeStyle="small")181 x += 100182 self.w.italicSlantOffset = EditText((x, y, 40, 22), '', sizeStyle="small", callback=self.calcItalicCallback)183 x += 60184 y += 30185 x = 10186 self.w.refresh = Button((x, y, 140, 22), u'Values from Current', callback=self.refresh, sizeStyle="small")187 y += 30188 self.w.fontSelection = RadioGroup((x, y, 120, 35), ['Current Font', 'All Fonts'], sizeStyle="small")189 self.w.fontSelection.set(0)190 x += 160191 self.w.glyphSelection = RadioGroup((x, y, 120, 55), ['Current Glyph', 'Selected Glyphs', 'All Glyphs'], sizeStyle="small")192 self.w.glyphSelection.set(0)193 y += 60194 x = 10195 self.w.setInFont = Button((x, y, 140, 22), 'Set Font Italic Values', sizeStyle="small", callback=self.setInFontCallback)196 x += 160197 self.w.italicize = Button((x, y, 140, 22), 'Italicize Glyphs', sizeStyle="small", callback=self.italicizeCallback)198 y += 25199 self.w.makeReferenceLayer = CheckBox((x, y, 145, 22), 'Make Reference Layer', value=getExtensionDefault(self.DEFAULTKEY_REFERENCE, False), sizeStyle="small", callback=self.makeReferenceLayerCallback)200 x = 10201 self.refresh()202 if self.getItalicAngle() == 0 and CurrentFont() is not None:203 self.setCrossHeight((CurrentFont().info.capHeight or 0) / 2)204 def makeReferenceLayerCallback(self, sender):205 setExtensionDefault(self.DEFAULTKEY_REFERENCE, sender.get())206 def italicizeCallback(self, sender=None):207 italicAngle = self.getItalicAngle()208 italicSlantOffset = self.getItalicSlantOffset()209 if self.w.fontSelection.get() == 0:210 if CurrentFont() is not None:211 fonts = [CurrentFont()]212 else:213 fonts = []214 else:215 fonts = AllFonts()216 if self.w.glyphSelection.get() == 0 and CurrentGlyph() is not None:217 glyphs = [CurrentGlyph()]218 elif self.w.glyphSelection.get() == 1:219 glyphs = []220 for f in fonts:221 for gname in CurrentFont().selection:222 if gname in f:223 glyphs.append(f[gname])224 else:225 glyphs = []226 for f in fonts:227 for g in f:228 glyphs.append(g.name)229 for glyph in glyphs:230 italicize(glyph, italicAngle,231 offset=italicSlantOffset,232 shouldMakeReferenceLayer=self.w.makeReferenceLayer.get())233 def refresh(self, sender=None):234 f = CurrentFont()235 if f:236 italicSlantOffset = f.lib.get(self.italicSlantOffsetKey) or 0237 italicAngle = f.info.italicAngle or 0238 crossHeight = calcCrossHeight(italicAngle=italicAngle,239 italicSlantOffset=italicSlantOffset)240 self.setItalicSlantOffset(italicSlantOffset)241 self.setItalicAngle(italicAngle)242 self.setCrossHeight(crossHeight)243 else:244 self.setItalicSlantOffset(0)245 self.setItalicAngle(0)246 self.setCrossHeight(0)247 self.updateBowtie()248 def setInFontCallback(self, sender):249 if self.w.fontSelection.get() == 0:250 if CurrentFont() is not None:251 fonts = [CurrentFont()]252 else:253 fonts = []254 else:255 fonts = AllFonts()256 for f in fonts:257 with f.undo('italicBowtie'):258 f.info.italicAngle = self.getItalicAngle()259 f.lib[self.italicSlantOffsetKey] = self.getItalicSlantOffset()260 try:261 window = CurrentGlyphWindow()262 window.setGlyph(CurrentGlyph().naked())263 except Exception:264 print(self.DEFAULTKEY, 'error resetting window, please refresh it')265 self.updateBowtie()266 def drawItalicBowtie(self, layer,267 italicAngle=0, crossHeight=0, italicSlantOffset=0,268 ascender=0, descender=0, xoffset=0):269 """270 Draw an italic Bowtie.271 """272 topBowtie = ascender273 topBowtieOffset = calcItalicOffset(topBowtie, italicAngle)274 bottomBowtie = descender275 bottomBowtieOffset = calcItalicOffset(bottomBowtie, italicAngle)276 pen = layer.getPen()277 pen.moveTo((xoffset, descender))278 pen.lineTo((xoffset+bottomBowtieOffset+italicSlantOffset, descender))279 pen.lineTo((xoffset+topBowtieOffset+italicSlantOffset, ascender))280 pen.lineTo((xoffset, ascender))281 pen.closePath()282 def calcItalicCallback(self, sender):283 italicAngle = self.getItalicAngle()284 italicSlantOffset = self.getItalicSlantOffset()285 if sender == self.w.crossHeightSetUC and CurrentFont() is not None:286 crossHeight = ( CurrentFont().info.capHeight or 0 ) / 2.0287 sender = self.w.crossHeight288 elif sender == self.w.crossHeightSetLC and CurrentFont() is not None:289 crossHeight = ( CurrentFont().info.xHeight or 0 ) / 2.0290 sender = self.w.crossHeight291 else:292 crossHeight = self.getCrossHeight()293 if sender == self.w.italicAngle or sender == self.w.italicSlantOffset:294 self.setCrossHeight(calcCrossHeight(italicAngle=italicAngle, italicSlantOffset=italicSlantOffset))295 elif sender == self.w.crossHeight:296 self.setItalicSlantOffset(calcItalicSlantOffset(italicAngle=italicAngle, crossHeight=crossHeight))297 self.setCrossHeight(crossHeight)298 self.updateBowtie()299 def updateBowtie(self):300 glyph = CurrentGlyph()301 italicAngle = self.getItalicAngle()302 italicSlantOffset = self.getItalicSlantOffset()303 crossHeight = self.getCrossHeight()304 ascender = glyph.font.info.ascender305 descender = glyph.font.info.descender306 italicSlantOffsetOffset = italicSlantOffset307 for xoffset, layer in [(0, self.leftBowtieLayer), (glyph.width, self.rightBowtieLayer)]:308 self.drawItalicBowtie(layer=layer,309 italicAngle=italicAngle,310 crossHeight=crossHeight,311 ascender=ascender,312 descender=descender,313 italicSlantOffset=italicSlantOffsetOffset,314 xoffset=xoffset)315 # crossheight316 self.crossHeightLayer.setStartPoint((0, crossHeight))317 self.crossHeightLayer.setEndPoint((glyph.width, crossHeight))318 ################################319 ################################320 ################################321 def getItalicAngle(self):322 a = self.w.italicAngle.get()323 try:324 return float(a)325 except ValueError:326 return 0327 def getItalicSlantOffset(self):328 a = self.w.italicSlantOffset.get()329 try:330 return float(a)331 except ValueError:332 return 0333 def getCrossHeight(self):334 a = self.w.crossHeight.get()335 try:336 return float(a)337 except ValueError:338 print('error', a)339 return 0340 def setItalicAngle(self, italicAngle):341 self.w.italicAngle.set(f'{italicAngle}')342 def setItalicSlantOffset(self, italicSlantOffset):343 self.w.italicSlantOffset.set(f'{italicSlantOffset}')344 def setCrossHeight(self, crossHeight):345 self.w.crossHeight.set(f'{crossHeight}')346if __name__ == '__main__':...

Full Screen

Full Screen

TextEditorWideInheritance.py

Source:TextEditorWideInheritance.py Github

copy

Full Screen

...363364 def bold(self):365 self.rich_text.swap_bold_state(self.textarea, self.text_obj_lst)366367 def italic(self):368 self.rich_text.swap_italic_state(self.textarea, self.text_obj_lst)369370if __name__ == "__main__":371 master = tk.Tk()372 pt = FileOperation(master) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful