Get meta-info from UIFont or CGFont - iOS, Swift - ios
I want to get meta info from fonts. For example: supported languages, version, license etc. How can I do this? It works fine on Mac Fonts app. I need to implement this on iOS.
You can get much of that information using CTFontCopyName. For example, you can print the font's copyright and license like this:
print(CTFontCopyName(font, kCTFontCopyrightNameKey))
print(CTFontCopyName(font, kCTFontLicenseNameKey))
The key constants are of the format kCTFont***NameKey and are declared in CTFont.h.
You can get the supported languages using CTFontCopySupportedLanguages, but you get a list of BCP-47 language identifiers:
import CoreText
import Foundation
let font = CTFontCreateWithName("Helvetica" as CFString, 12, nil)
let languageIds = CTFontCopySupportedLanguages(font) as! [String]
print(languageIds.joined(separator: ", "))
// Output:
af, agq, ak, asa, ast, az, bas, be, bem, bez, bg, bm, br, bs, ca, ce, cgg, cs, cy, da, dav, de, dje, dsb, dyo, ebu, el, en, eo, es, et, eu, ewo, fi, fil, fo, fr, fur, fy, ga, gd, gl, gsw, guz, gv, haw, hr, hsb, hu, id, ig, is, it, jmc, ka, kam, kde, kea, khq, ki, kk, kl, kln, ksb, ksf, ksh, kw, lag, lb, lg, lkt, ln, lt, lu, luo, luy, lv, mas, mer, mfe, mg, mgh, mgo, mk, mn, ms, mt, naq, nb, nd, nl, nmg, nn, nnh, nyn, om, os, pl, pt, qu, rm, rn, ro, rof, ru, rw, rwk, saq, sbp, se, seh, ses, sg, sk, sl, smn, sn, so, sq, sr, sv, sw, teo, tg, tk, to, tr, twq, uk, uz, vi, vun, wae, xog, yav, yo, zu
You can convert them to human-readable language names by using a Locale. You probably want to use the system locale, chosen by the user:
let myLocale = Locale.autoupdatingCurrent
let languageNames = languageIds.compactMap({ myLocale.localizedString(forLanguageCode: $0) })
print(languageNames.joined(separator: ", "))
// Output:
Afrikaans, Aghem, Akan, Asu, Asturian, Azerbaijani, Basaa, Belarusian, Bemba, Bena, Bulgarian, Bambara, Breton, Bosnian, Catalan, Chechen, Chiga, Czech, Welsh, Danish, Taita, German, Zarma, Lower Sorbian, Jola-Fonyi, Embu, Greek, English, Esperanto, Spanish, Estonian, Basque, Ewondo, Finnish, Filipino, Faroese, French, Friulian, Western Frisian, Irish, Scottish Gaelic, Galician, Swiss German, Gusii, Manx, Hawaiian, Croatian, Upper Sorbian, Hungarian, Indonesian, Igbo, Icelandic, Italian, Machame, Georgian, Kamba, Makonde, Kabuverdianu, Koyra Chiini, Kikuyu, Kazakh, Kalaallisut, Kalenjin, Shambala, Bafia, Colognian, Cornish, Langi, Luxembourgish, Ganda, Lakota, Lingala, Lithuanian, Luba-Katanga, Luo, Luyia, Latvian, Masai, Meru, Morisyen, Malagasy, Makhuwa-Meetto, Metaʼ, Macedonian, Mongolian, Malay, Maltese, Nama, Norwegian Bokmål, North Ndebele, Dutch, Kwasio, Norwegian Nynorsk, Ngiemboon, Nyankole, Oromo, Ossetic, Polish, Portuguese, Quechua, Romansh, Rundi, Romanian, Rombo, Russian, Kinyarwanda, Rwa, Samburu, Sangu, Northern Sami, Sena, Koyraboro Senni, Sango, Slovak, Slovenian, Inari Sami, Shona, Somali, Albanian, Serbian, Swedish, Swahili, Teso, Tajik, Turkmen, Tongan, Turkish, Tasawaq, Ukrainian, Uzbek, Vietnamese, Vunjo, Walser, Soga, Yangben, Yoruba, Zulu
I don't know how to get the scripts supported by a font.
Related
How to find a string from a specific word to other word using rails
I have the following string and I'm trying to display the information from specific start word to specific end word: Protocolo de medición \r\n\r\nEnsayador disruptivo \r\nDPA 75C Versión: 1.07 \r\nNúmero de serie: 1101908010 \r\n11/02/2022 02:15\r\n_____________________________ \r\n\r\nInformación sobre el ensayo \r\n\r\nNombre de protocolo: ....................... \r\nNúmero de muestra: 0569.1 \r\nMedición según norma: ASTM D1816:2004 2mm \r\nForma de electrodos: Forma de seta \r\nDistancia entre electrodos: 2 mm \r\nFrec. del ensayo: 60 Hz\r\n\r\n_____________________________ \r\n\r\nConfig. según norma \r\n\r\nDiámetro de los electrodos: 36 mm\r\n\r\n_____________________________ \r\n\r\nValores de medición \r\n\r\nTemperatura: 20 °C \r\n\r\nMedición 1: 60.6 kV \r\nMedición 2: 72.7 kV\r\nMedición 3: >75.0 kV \r\nMedición 4: 54.7 kV\r\nMedición 5: 66.4 kV \r\n\r\nValor medio: 65.9 kV \r\nDesviación estándar: 8.4 kV \r\nDesviación estándar/val. medio: 12.8 % \r\n\r\n\r\nEnsayo correctamente realiz. \r\n\r\n\r\nEnsayo ejecutado por: ....................... The code should find the string line \r\nNúmero de muestra: 0569.1 \r\ Final result should be 0569.1 I tried this code only display the word searched #article.description.match(/Número de muestra:\b/) I tried this code and works but i need to count the number from and to <%= #article.description.slice(249..260) %> What i want is write the FROM WORD - TO WORD string without typing the index word.
If the string you are looking to capture always has a line end character after it at some point you can do: data = #article.description.match(/Número de muestra:*(.*)$/) returns a Match object like: #<MatchData "Número de muestra: 0569.1" 1:"0569.1"> you can then access the match with data[1] # => "0569.1" The Match object stores the matching string in data[0] and the first capture is in data[1]. In the regexp we are using the .* matches the spaces after the string Número de muestra:. The (.*) matches any characters after the spaces. The $ matches the end of line character. Anything that matches what is between the parens () gets stored as matches in the Match object.
Year of publication not appearing in the list of references at the end of a compiled LaTeX document using bibliographystyle{naturemag}
I'm new to LaTex, so I am using overleaf to create my citations. My bibliographystyle is naturemag. My references are not including the year of publication in the reference list. Here is an example of the output I am seeing. Cite these [1, 2] References [1] Claw, K. et al. A framework for enhancing ethical genomic research with indigenous communities. Nature Communications 9, 2957. URL https://doi.org/10.1038/s41467-018-05188-3. [2] Tsosie, K., Yracheta, J., Kolopenuk, J. & Smith, R. Indigenous data sovereignties and data sharing in biological anthropology. American Journal of Physical Anthropology 174, 183–186. URL https://doi.org/10.1002/ajpa2484. 1 Below is a sample of my bib.bib bibliography file #article{claw2018a, author = {Claw, K.G. and Anderson, M.Z. and Begay, R.L. and Tsosie, K.S. and Fox, K. and Garrison, N.A. and Consortium, S.internship for In peoples in G.}, title = {A framework for enhancing ethical genomic research with Indigenous communities}, volume = {9}, pages = {2957}, url = {https://doi.org/10.1038/s41467-018-05188-3}, doi = {10.1038/s41467-018-05188-3}, language = {en}, journal = {Nature Communications}, number = {1}, date = {2018} } #article{tsosie2021b, author = {Tsosie, K.S. and Yracheta, J.M. and Kolopenuk, J.A. and Smith, R.W.}, date = {2021}, title = {Indigenous data sovereignties and data sharing in biological anthropology}, volume = {174}, pages = {183–186}, url = {https://doi.org/10.1002/ajpa2484}, doi = {10.1002/ajpa2484}, language = {en}, journal = {American Journal of Physical Anthropology}, number = {2} } Below are the LaTeX commands I am running. \documentclass{article} \usepackage[utf8]{inputenc} \title{paper} \author{author} \date{February 2022} \begin{document} \maketitle Cite these \cite{claw2018a,tsosie2021b} \bibliographystyle{naturemag} \bibliography{bib.bib} \end{document}
You are using bibtex and not biblatex, so you need to use the less flexible year field instead of the date field: #article{claw2018a, author = {Claw, K.G. and Anderson, M.Z. and Begay, R.L. and Tsosie, K.S. and Fox, K. and Garrison, N.A. and Consortium, S.internship for In peoples in G.}, title = {A framework for enhancing ethical genomic research with Indigenous communities}, volume = {9}, pages = {2957}, url = {https://doi.org/10.1038/s41467-018-05188-3}, doi = {10.1038/s41467-018-05188-3}, language = {en}, journal = {Nature Communications}, number = {1}, year = {2018} } #article{tsosie2021b, author = {Tsosie, K.S. and Yracheta, J.M. and Kolopenuk, J.A. and Smith, R.W.}, year = {2021}, title = {Indigenous data sovereignties and data sharing in biological anthropology}, volume = {174}, pages = {183–186}, url = {https://doi.org/10.1002/ajpa2484}, doi = {10.1002/ajpa2484}, language = {en}, journal = {American Journal of Physical Anthropology}, number = {2} }
convert utf codes to letters
I'm using Ruby I have such value in the database 25.02.2020 13:57:56:\nu:633;644;627;645; u:627;633;62a;627;62f; u:645;6cc;634;647; u:644;637;641; u:6a9;646;6cc;62f; u:622;645;648;632;634; u:6a9;627;631; u:628;627; u:627;6cc;646; u:628;631;646;627;645;647; u:627;632; u:635;641;631; u:62a;627; u:635;62f; u:631;648; u:628;641;631;645;627;6cc;6cc;62f; u:645;645;646;648;646; u:627;632; u:634;645;627;\n\n\nСервис is it possible to convert it to normal persian letters with a ruby? it must be like this 13:57:56: سلام استاد میشه لطف کنید آموزش کار با این برنامه از صفر تا صد رو بفرمایید ممنون از شما Сервис I will be appreciative for your help
The Unicode values in your string have a specific pattern: u:___;___;___; where each ___ is a hexadecimal value representing a codepoint. You can match that pattern using a regexp, and replace the encoded values with their respective Unicode chars via gsub: str = '25.02.2020 13:57:56:\nu:633;644;627;645; u:627;633;62a;627;62f; u:645;6cc;634;647; u:644;637;641; u:6a9;646;6cc;62f; u:622;645;648;632;634; u:6a9;627;631; u:628;627; u:627;6cc;646; u:628;631;646;627;645;647; u:627;632; u:635;641;631; u:62a;627; u:635;62f; u:631;648; u:628;641;631;645;627;6cc;6cc;62f; u:645;645;646;648;646; u:627;632; u:634;645;627;\n\n\nСервис' str.gsub(/u:((?:\h+;)+)/) { Regexp.last_match(1).split(';').map(&:hex).pack('U*') } #=> "25.02.2020 13:57:56:\\nسلام استاد میشه لطف کنید آموزش کار با این برنامه از صفر تا صد رو بفرمایید ممنون از شما\\n\\n\\nСервис" Step by step: (for each match) the regexp matches "u:633;644;627;645;" Regexp.last_match(1) returns the 1st capture group "633;644;627;645;" split(';') turns that into ["633", "644", "627", "645"] map(&:hex) converts the elements to [1587, 1604, 1575, 1605] pack('U*') interprets them as Unicode codepoints and returns "سلام"
convert bib file to \bibitem[\protect\citeauthoryear
I have a reference file (bib file) I want to convert it as \bibitem[\protect\citeauthoryear{Allen C.W.}{1973}] {b1} Allen C.W., 1973, Astrophysical quantities, ${3^{rd}}$ ed. (Athlone Press, London) when I use \nocite{*} \bibliographystyle{apalike} \bibliography{bibfile} Output ppl file as \bibitem[Allen, 1973]{allen1973astrophysical} Allen, C.~W. (1973).
Combining natbib with the newapa style gives something similar: \documentclass{article} \usepackage{filecontents} \begin{filecontents*}{\jobname.bib} #BOOK{1973asqu.book.....A, author = {{Allen}, C.~W.}, title = "{Astrophysical quantities}", keywords = {ASTROPHYSICS, ASTRONOMICAL CONSTANTS, TABLES, HANDBOOKS}, booktitle = {London: University of London, Athlone Press, |c1973, 3rd ed.}, year = 1973, adsurl = {https://ui.adsabs.harvard.edu/abs/1973asqu.book.....A}, adsnote = {Provided by the SAO/NASA Astrophysics Data System} } \end{filecontents*} \usepackage{natbib} \begin{document} \cite{1973asqu.book.....A} \bibliographystyle{newapa} \bibliography{\jobname} \end{document} Resulting .bbl file: \begin{thebibliography}{} \bibitem[\protect\citeauthoryear{{Allen}}{{Allen}}{1973}]{1973asqu.book.....A} {Allen}, C.~W. (1973). \newblock {\em {Astrophysical quantities}}. \end{thebibliography}
Can I search countries by country_code in AdWords API v201603?
I want to estimate searches for a keyword, limited to a country. A similar question was asked about 4 years ago: Can I search countries by country_code in AdWords API v201109?. The accepted answer was: it is not currently possible. We are now at version v201603, and I wonder if there is a change. In my specific case I code in Java, but will appreciate the answer in any language, I'll be able to find the relevant Java counterpart. Update: To add to the accepted answer, here is the list of the country codes extracted from AdWords CSV file. private static HashMap<String, Long> COUNTRIES = new HashMap<String, Long>() { { put("ad",2020L); //,Andorra put("ae",2784L); //,United Arab Emirates put("af",2004L); //,Afghanistan put("ag",2028L); //,Antigua and Barbuda put("al",2008L); //,Albania put("am",2051L); //,Armenia put("ao",2024L); //,Angola put("aq",2010L); //,Antarctica put("ar",2032L); //,Argentina put("as",2016L); //,American Samoa put("at",2040L); //,Austria put("au",2036L); //,Australia put("az",2031L); //,Azerbaijan put("ba",2070L); //,Bosnia and Herzegovina put("bb",2052L); //,Barbados put("bd",2050L); //,Bangladesh put("be",2056L); //,Belgium put("bf",2854L); //,Burkina Faso put("bg",2100L); //,Bulgaria put("bh",2048L); //,Bahrain put("bi",2108L); //,Burundi put("bj",2204L); //,Benin put("bn",2096L); //,Brunei put("bo",2068L); //,Bolivia put("br",2076L); //,Brazil put("bs",2044L); //,The Bahamas put("bt",2064L); //,Bhutan put("bw",2072L); //,Botswana put("by",2112L); //,Belarus put("bz",2084L); //,Belize put("ca",2124L); //,Canada put("cc",2166L); //,Cocos (Keeling) Islands put("cd",2180L); //,Democratic Republic of the Congo put("cf",2140L); //,Central African Republic put("cg",2178L); //,Republic of the Congo put("ch",2756L); //,Switzerland put("ci",2384L); //,Cote d'Ivoire put("ck",2184L); //,Cook Islands put("cl",2152L); //,Chile put("cm",2120L); //,Cameroon put("cn",2156L); //,China put("co",2170L); //,Colombia put("cr",2188L); //,Costa Rica put("cv",2132L); //,Cape Verde put("cx",2162L); //,Christmas Island put("cy",2196L); //,Cyprus put("cz",2203L); //,Czech Republic put("de",2276L); //,Germany put("dj",2262L); //,Djibouti put("dk",2208L); //,Denmark put("dm",2212L); //,Dominica put("do",2214L); //,Dominican Republic put("dz",2012L); //,Algeria put("ec",2218L); //,Ecuador put("ee",2233L); //,Estonia put("eg",2818L); //,Egypt put("er",2232L); //,Eritrea put("es",2724L); //,Spain put("et",2231L); //,Ethiopia put("fi",2246L); //,Finland put("fj",2242L); //,Fiji put("fm",2583L); //,Federated States of Micronesia put("fr",2250L); //,France put("ga",2266L); //,Gabon put("gb",2826L); //,United Kingdom put("gd",2308L); //,Grenada put("ge",2268L); //,Georgia put("gh",2288L); //,Ghana put("gm",2270L); //,The Gambia put("gn",2324L); //,Guinea put("gq",2226L); //,Equatorial Guinea put("gr",2300L); //,Greece put("gs",2239L); //,South Georgia and the South Sandwich Islands put("gt",2320L); //,Guatemala put("gu",2316L); //,Guam put("gw",2624L); //,Guinea-Bissau put("gy",2328L); //,Guyana put("hm",2334L); //,Heard Island and McDonald Islands put("hn",2340L); //,Honduras put("hr",2191L); //,Croatia put("ht",2332L); //,Haiti put("hu",2348L); //,Hungary put("id",2360L); //,Indonesia put("ie",2372L); //,Ireland put("il",2376L); //,Israel put("in",2356L); //,India put("iq",2368L); //,Iraq put("is",2352L); //,Iceland put("it",2380L); //,Italy put("jm",2388L); //,Jamaica put("jo",2400L); //,Jordan put("jp",2392L); //,Japan put("ke",2404L); //,Kenya put("kg",2417L); //,Kyrgyzstan put("kh",2116L); //,Cambodia put("ki",2296L); //,Kiribati put("km",2174L); //,Comoros put("kn",2659L); //,Saint Kitts and Nevis put("kr",2410L); //,South Korea put("kw",2414L); //,Kuwait put("kz",2398L); //,Kazakhstan put("la",2418L); //,Laos put("lb",2422L); //,Lebanon put("lc",2662L); //,Saint Lucia put("li",2438L); //,Liechtenstein put("lk",2144L); //,Sri Lanka put("lr",2430L); //,Liberia put("ls",2426L); //,Lesotho put("lt",2440L); //,Lithuania put("lu",2442L); //,Luxembourg put("lv",2428L); //,Latvia put("ly",2434L); //,Libya put("ma",2504L); //,Morocco put("mc",2492L); //,Monaco put("md",2498L); //,Moldova put("me",2499L); //,Montenegro put("mg",2450L); //,Madagascar put("mh",2584L); //,Marshall Islands put("mk",2807L); //,Macedonia (fyroM) put("ml",2466L); //,Mali put("mn",2496L); //,Mongolia put("mp",2580L); //,Northern Mariana Islands put("mr",2478L); //,Mauritania put("mt",2470L); //,Malta put("mu",2480L); //,Mauritius put("mv",2462L); //,Maldives put("mw",2454L); //,Malawi put("mx",2484L); //,Mexico put("my",2458L); //,Malaysia put("mz",2508L); //,Mozambique put("na",2516L); //,Namibia put("nc",2540L); //,New Caledonia put("ne",2562L); //,Niger put("nf",2574L); //,Norfolk Island put("ng",2566L); //,Nigeria put("ni",2558L); //,Nicaragua put("nl",2528L); //,Netherlands put("no",2578L); //,Norway put("np",2524L); //,Nepal put("nr",2520L); //,Nauru put("nu",2570L); //,Niue put("nz",2554L); //,New Zealand put("om",2512L); //,Oman put("pa",2591L); //,Panama put("pe",2604L); //,Peru put("pf",2258L); //,French Polynesia put("pg",2598L); //,Papua New Guinea put("ph",2608L); //,Philippines put("pk",2586L); //,Pakistan put("pl",2616L); //,Poland put("pm",2666L); //,Saint Pierre and Miquelon put("pn",2612L); //,Pitcairn Islands put("pt",2620L); //,Portugal put("pw",2585L); //,Palau put("py",2600L); //,Paraguay put("qa",2634L); //,Qatar put("ro",2642L); //,Romania put("rs",2688L); //,Serbia put("ru",2643L); //,Russia put("rw",2646L); //,Rwanda put("sa",2682L); //,Saudi Arabia put("sb",2090L); //,Solomon Islands put("sc",2690L); //,Seychelles put("se",2752L); //,Sweden put("sg",2702L); //,Singapore put("sh",2654L); //,Saint Helena put("si",2705L); //,Slovenia put("sk",2703L); //,Slovakia put("sl",2694L); //,Sierra Leone put("sm",2674L); //,San Marino put("sn",2686L); //,Senegal put("so",2706L); //,Somalia put("sr",2740L); //,Suriname put("st",2678L); //,Sao Tome and Principe put("sv",2222L); //,El Salvador put("sz",2748L); //,Swaziland put("td",2148L); //,Chad put("tf",2260L); //,French Southern and Antarctic Lands put("tg",2768L); //,Togo put("th",2764L); //,Thailand put("tj",2762L); //,Tajikistan put("tk",2772L); //,Tokelau put("tl",2626L); //,Timor-Leste put("tm",2795L); //,Turkmenistan put("tn",2788L); //,Tunisia put("to",2776L); //,Tonga put("tr",2792L); //,Turkey put("tt",2780L); //,Trinidad and Tobago put("tv",2798L); //,Tuvalu put("tz",2834L); //,Tanzania put("ua",2804L); //,Ukraine put("ug",2800L); //,Uganda put("um",2581L); //,United States Minor Outlying Islands put("us",2840L); //,United States put("uy",2858L); //,Uruguay put("uz",2860L); //,Uzbekistan put("va",2336L); //,Vatican City put("vc",2670L); //,Saint Vincent and the Grenadines put("ve",2862L); //,Venezuela put("vn",2704L); //,Vietnam put("vu",2548L); //,Vanuatu put("wf",2876L); //,Wallis and Futuna put("ws",2882L); //,Samoa put("ye",2887L); //,Yemen put("za",2710L); //,South Africa put("zm",2894L); //,Zambia put("zw",2716L); //,Zimbabwe } };
Yes - you can use the Targeting Idea Service to specify any location code (which includes countries, regions, cities, etc) for a Search Volume based query. I am unfamiliar with the Java client library but I am sure it will be similar to the .NET one. The C# code below outputs the search volume for the terms 'blue fedora' and 'red fedora' for queries based in Canada. var targettingIdeaSvc = (TargetingIdeaService)awUser.GetService(AdWordsService.v201601.TargetingIdeaService); var searchQueries = new string[] { "blue fedora", "red fedora" }; var ideasPg = targettingIdeaSvc.get(new TargetingIdeaSelector { ideaType = IdeaType.KEYWORD, requestType = RequestType.STATS, requestedAttributeTypes = new AttributeType[] { AttributeType.SEARCH_VOLUME }, searchParameters = new SearchParameter[] { new RelatedToQuerySearchParameter { queries = searchQueries, }, new LocationSearchParameter { locations = new Location[] { new Location { id = 2124 // This is the location id for Canada - comprehensive list of location ids is available here https://developers.google.com/adwords/api/docs/appendix/geotargeting } } }, }, paging = new Paging { numberResults = 5, startIndex = 0 } }); for (var i = 0; i < searchQueries.Length; i++) { var searchVolume = (ideasPg.entries[i].data.First().value as LongAttribute).value; Console.WriteLine($#"Search Term: ""{searchQueries[i]}"" has search volume of {searchVolume} in Canada"); } This service uses a location id. You can look up a specific id from the AdWords Geo-Location reference page (or even access this list programatically if you need to)