{"id":23900701,"url":"https://github.com/pcjbird/fbcharm","last_synced_at":"2025-10-07T00:24:01.123Z","repository":{"id":56932023,"uuid":"161879289","full_name":"pcjbird/fbCharm","owner":"pcjbird","description":"The fallback mechanism with iOS is used to set fonts for different languages (script), thereby making text mixing typography more elegant. iOS 上利用 fallback 机制为不同语言的文字 (script) 设定字体，从而使得文本混排更为优雅。","archived":false,"fork":false,"pushed_at":"2021-04-15T02:31:55.000Z","size":14414,"stargazers_count":54,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-06T10:44:58.258Z","etag":null,"topics":["charm","chinese","composited","css","custom","different","english","fallback","family","font","font-family","ios","japanese","language","mix","nsattributedstring","script","string","text","uilabel"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pcjbird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-15T07:01:25.000Z","updated_at":"2025-04-29T09:18:59.000Z","dependencies_parsed_at":"2022-08-21T00:00:29.842Z","dependency_job_id":null,"html_url":"https://github.com/pcjbird/fbCharm","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/pcjbird/fbCharm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcjbird%2FfbCharm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcjbird%2FfbCharm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcjbird%2FfbCharm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcjbird%2FfbCharm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcjbird","download_url":"https://codeload.github.com/pcjbird/fbCharm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcjbird%2FfbCharm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278702928,"owners_count":26031201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charm","chinese","composited","css","custom","different","english","fallback","family","font","font-family","ios","japanese","language","mix","nsattributedstring","script","string","text","uilabel"],"created_at":"2025-01-04T20:36:39.407Z","updated_at":"2025-10-07T00:24:01.089Z","avatar_url":"https://github.com/pcjbird.png","language":"Swift","readme":"![logo](https://github.com/pcjbird/fbCharm/raw/master/logo.png)\n[![Build Status](http://img.shields.io/travis/pcjbird/fbCharm/master.svg?style=flat)](https://travis-ci.org/pcjbird/fbCharm)\n[![Pod Version](http://img.shields.io/cocoapods/v/fbCharm.svg?style=flat)](http://cocoadocs.org/docsets/fbCharm/)\n[![Pod Platform](http://img.shields.io/cocoapods/p/fbCharm.svg?style=flat)](http://cocoadocs.org/docsets/fbCharm/)\n[![Pod License](http://img.shields.io/cocoapods/l/fbCharm.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html)\n[![GitHub release](https://img.shields.io/github/release/pcjbird/fbCharm.svg)](https://github.com/pcjbird/fbCharm/releases)\n[![GitHub release](https://img.shields.io/github/release-date/pcjbird/fbCharm.svg)](https://github.com/pcjbird/fbCharm/releases)\n[![Website](https://img.shields.io/website-pcjbird-down-green-red/https/shields.io.svg?label=author)](https://pcjbird.github.io)\n\n# fbCharm (Charm of Fallback)\n### iOS 上利用 fallback 机制为不同语言的文字 (script) 设定字体，从而使得文本混排更为优雅。\n\n如果您是一位 WEB 开发者，相信您对 CSS 的 font-family 属性一定不会陌生。通常我们会为 font-family 属性设置一长串的字体(家族)列表，就像这样的：\n\n```css\n.text { font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Arial, \"Microsoft YaHei\", \"黑体\", \"宋体\", sans-serif; }\n```\n\n有人肯定会问，为什么要这么设置啊？如果你足够细心，你一定会发现当你浏览该网页时英文字体和中文字体并不是同一种字体，如果你在不同的操作系统甚至不同的电脑上看到网页所呈现的字体也不一样。这又是为什么呢？\n\n此外，在您使用 Microsoft Word 进行段落排版的时候，你会发现 Word 可以自动对中文样式应用中文字体，对英文样式应用英文字体。这又是如何做到的呢？\n\n在实际的排版需求中，为了好看，我们通常会需要针对不同语言的文字 (script) 进行不同的字体设定，以达到最佳的视觉效果。当然，对于我们来说，最常见的还是中英文混排。通常设计人员给出的设计稿非常漂亮，可是中英文使用了不同的字体，我们开发人员该如何高保真地还原设计稿的原始设计呢？\n\n很显然，对于 WEB 开发者来说，已经有了很好的解决方案，而对于其他客户端的同学来说，这估计应该就有点犯难了，我们通常会告诉设计人员：“系统不支持” 抑或 “做不了” 之类的话。那事实上，到底能不能做到呢？答案是肯定的。\n\n## 特性 / Features\n\n1. 支持类似 CSS 的 font-family 属性一样设置一个字体家族 (font-family) 列表或字体名称 (font-name) 列表从而创建一个混合字体 (UIFont)。\n2. 支持同样的方式创建带样式的NSAttributedString，支持设置文本间隔 (kern), 字重 (weight) 等。\n3. 支持 fallback 到指定的系统字体。\n\n## 演示 / Demo\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/pcjbird/fbCharm/raw/master/demo.gif\" title=\"demo\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/pcjbird/fbCharm/raw/master/demo.png\" title=\"demo\"\u003e\u003c/p\u003e\n\n##  安装 / Installation\n\n方法一：`fbCharm` is available through CocoaPods. To install it, simply add the following line to your Podfile:\n```\npod 'fbCharm'\n```\n## 使用 / Usage\n```swift\nlet text = \"これは日本語文章と Roman Text の混植文章です。美しいヒラギノと San Francisco で日本語とローマ字を書きます。System Font のフォントメトリクスには独自の調整が入っています。\\n\\n这是一段中文简体。\\n這是一段中文繁體。\\nうつくしい森で飾られたモーリオ市、\\n郊外のぎらぎらひかる草の波。\\n祇辻飴葛蛸鯖鰯噌庖箸\\n底辺直卿蝕薩化\\nABCDEFGHIJKLM\\nabcdefghijklm\\n1234567890\\niClockᴹᴵᴺᴵ\\nClockª\"\nlet fontSize: CGFloat = 22.0\n\n// 適当に行間を空ける処理\nlet paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()\nparagraphStyle.minimumLineHeight = fontSize * 1.5\nparagraphStyle.maximumLineHeight = paragraphStyle.minimumLineHeight\n\nlet attributedString = NSMutableAttributedString(text: text, families: [\"Lucida Grande\", \"Baskerville\", \"Apple SD Gothic Neo\"], size: 18.0, weight: .light, kern: 4.0, paragraphStyle: paragraphStyle)\nself.label.attributedText = attributedString\n\n//let font = UIFont(families: [\"Lucida Grande\", \"Baskerville\", \"Apple SD Gothic Neo\"], size: 20, weight: .medium)\n//self.label.font = font\n//self.label.text = text\n```\n## 关注我们 / Follow us\n  \n  \u003ca href=\"https://itunes.apple.com/cn/app/iclock-一款满足-挑剔-的翻页时钟与任务闹钟/id1128196970?pt=117947806\u0026ct=com.github.pcjbird.fbCharm\u0026mt=8\"\u003e\u003cimg src=\"https://github.com/pcjbird/AssetsExtractor/raw/master/iClock.gif\" width=\"400\" title=\"iClock - 一款满足“挑剔”的翻页时钟与任务闹钟\"\u003e\u003c/a\u003e    \n  \n  [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=https://github.com/pcjbird/fbCharm)\n  [![Twitter Follow](https://img.shields.io/twitter/follow/pcjbird.svg?style=social)](https://twitter.com/pcjbird)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcjbird%2Ffbcharm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcjbird%2Ffbcharm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcjbird%2Ffbcharm/lists"}