{"action":"created","comment":{"url":"https://api.github.com/repos/google/xi-mac/pulls/comments/116153027","pull_request_review_id":37753546,"id":116153027,"diff_hunk":"@@ -16,11 +16,55 @@ import Cocoa\n \n /// A represents a given text style.\n struct Style {\n-    var fgColor: NSColor;\n-    var bgColor: NSColor;\n-    var weight: UInt16;\n-    var underline: Bool;\n-    var italic: Bool;\n+    var font: NSFont?\n+    var fgColor: NSColor?\n+    var bgColor: NSColor?\n+    var underline: Bool\n+    var italic: Bool\n+    var weight: Int?\n+    var attributes: [String: Any] = [:]\n+\n+    init(font fromFont: NSFont, fgColor: NSColor?, bgColor: NSColor?, underline: Bool, italic: Bool, weight: Int?) {\n+        if let fgColor = fgColor {\n+            attributes[NSForegroundColorAttributeName] = fgColor\n+        }\n+\n+        if let bgColor = bgColor, bgColor.alphaComponent != 0.0 {\n+            attributes[NSBackgroundColorAttributeName] = bgColor\n+        }\n+\n+        if underline {\n+            attributes[NSUnderlineStyleAttributeName] = NSUnderlineStyle.styleSingle.rawValue\n+        }\n+\n+        let fm = NSFontManager.shared()\n+        var font: NSFont?\n+\n+        if italic {\n+            var traits = fm.traits(of: fromFont)\n+            traits.insert(NSFontTraitMask.italicFontMask)\n+            if let f = closestMatch(of: fromFont, traits: traits, weight: weight ?? fm.weight(of: fromFont)) {\n+                font = f\n+            } else {\n+                attributes[NSObliquenessAttributeName] = 0.2\n+            }\n+        }\n+\n+        if font == nil && weight != nil {\n+            font = closestMatch(of: fromFont, traits: fm.traits(of: fromFont), weight: weight!) ?? fromFont","path":"XiEditor/StyleMap.swift","position":44,"original_position":44,"commit_id":"0d4ebf6032c0390dd779c7a3614d21081e7a84c9","original_commit_id":"0d4ebf6032c0390dd779c7a3614d21081e7a84c9","user":{"login":"rkusa","id":409021,"avatar_url":"https://avatars2.githubusercontent.com/u/409021?v=3","gravatar_id":"","url":"https://api.github.com/users/rkusa","html_url":"https://github.com/rkusa","followers_url":"https://api.github.com/users/rkusa/followers","following_url":"https://api.github.com/users/rkusa/following{/other_user}","gists_url":"https://api.github.com/users/rkusa/gists{/gist_id}","starred_url":"https://api.github.com/users/rkusa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkusa/subscriptions","organizations_url":"https://api.github.com/users/rkusa/orgs","repos_url":"https://api.github.com/users/rkusa/repos","events_url":"https://api.github.com/users/rkusa/events{/privacy}","received_events_url":"https://api.github.com/users/rkusa/received_events","type":"User","site_admin":false},"body":"Actually, the `?? fromFont` wasn't supposed to be there anymore, since I prefer to not set the `NSFontAttributeName` if the default font is used. I'll remove it","created_at":"2017-05-12T04:57:29Z","updated_at":"2017-05-12T04:57:29Z","html_url":"https://github.com/google/xi-mac/pull/32#discussion_r116153027","pull_request_url":"https://api.github.com/repos/google/xi-mac/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/google/xi-mac/pulls/comments/116153027"},"html":{"href":"https://github.com/google/xi-mac/pull/32#discussion_r116153027"},"pull_request":{"href":"https://api.github.com/repos/google/xi-mac/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/google/xi-mac/pulls/32","id":119235671,"html_url":"https://github.com/google/xi-mac/pull/32","diff_url":"https://github.com/google/xi-mac/pull/32.diff","patch_url":"https://github.com/google/xi-mac/pull/32.patch","issue_url":"https://api.github.com/repos/google/xi-mac/issues/32","number":32,"state":"open","locked":false,"title":"Use font based on italic and font weight settings","user":{"login":"rkusa","id":409021,"avatar_url":"https://avatars2.githubusercontent.com/u/409021?v=3","gravatar_id":"","url":"https://api.github.com/users/rkusa","html_url":"https://github.com/rkusa","followers_url":"https://api.github.com/users/rkusa/followers","following_url":"https://api.github.com/users/rkusa/following{/other_user}","gists_url":"https://api.github.com/users/rkusa/gists{/gist_id}","starred_url":"https://api.github.com/users/rkusa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkusa/subscriptions","organizations_url":"https://api.github.com/users/rkusa/orgs","repos_url":"https://api.github.com/users/rkusa/repos","events_url":"https://api.github.com/users/rkusa/events{/privacy}","received_events_url":"https://api.github.com/users/rkusa/received_events","type":"User","site_admin":false},"body":"This PR is not ready, yet, but I'd like to have some feedback before continuing it (if continuing at all).\r\n\r\nI've started working on the following code comments\r\n\r\n```\r\n// TODO: apply actual numeric weight\r\n// TODO: use true italic in font if available\r\n```\r\n\r\n... and implemented the changes while keeping the future required string width calculation in mind.\r\n\r\nThe main concern is maybe that I made the `Style` struct font-aware. While this does work well for style-spans, it does not work well with the current `TextDrawingMetrics` that lives in the `EditViewController`. My feeling is that the `TextDrawingMetrics` could be replaced with a default Style (maybe Style 0 as the default style, and 1 the selection).","created_at":"2017-05-05T18:45:17Z","updated_at":"2017-05-12T04:57:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"351e2149e7b3ae3157ded5e9f8e1eb150cb717f9","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/google/xi-mac/pulls/32/commits","review_comments_url":"https://api.github.com/repos/google/xi-mac/pulls/32/comments","review_comment_url":"https://api.github.com/repos/google/xi-mac/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/xi-mac/issues/32/comments","statuses_url":"https://api.github.com/repos/google/xi-mac/statuses/0d4ebf6032c0390dd779c7a3614d21081e7a84c9","head":{"label":"rkusa:style_font","ref":"style_font","sha":"0d4ebf6032c0390dd779c7a3614d21081e7a84c9","user":{"login":"rkusa","id":409021,"avatar_url":"https://avatars2.githubusercontent.com/u/409021?v=3","gravatar_id":"","url":"https://api.github.com/users/rkusa","html_url":"https://github.com/rkusa","followers_url":"https://api.github.com/users/rkusa/followers","following_url":"https://api.github.com/users/rkusa/following{/other_user}","gists_url":"https://api.github.com/users/rkusa/gists{/gist_id}","starred_url":"https://api.github.com/users/rkusa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkusa/subscriptions","organizations_url":"https://api.github.com/users/rkusa/orgs","repos_url":"https://api.github.com/users/rkusa/repos","events_url":"https://api.github.com/users/rkusa/events{/privacy}","received_events_url":"https://api.github.com/users/rkusa/received_events","type":"User","site_admin":false},"repo":{"id":88975425,"name":"xi-mac","full_name":"rkusa/xi-mac","owner":{"login":"rkusa","id":409021,"avatar_url":"https://avatars2.githubusercontent.com/u/409021?v=3","gravatar_id":"","url":"https://api.github.com/users/rkusa","html_url":"https://github.com/rkusa","followers_url":"https://api.github.com/users/rkusa/followers","following_url":"https://api.github.com/users/rkusa/following{/other_user}","gists_url":"https://api.github.com/users/rkusa/gists{/gist_id}","starred_url":"https://api.github.com/users/rkusa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkusa/subscriptions","organizations_url":"https://api.github.com/users/rkusa/orgs","repos_url":"https://api.github.com/users/rkusa/repos","events_url":"https://api.github.com/users/rkusa/events{/privacy}","received_events_url":"https://api.github.com/users/rkusa/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rkusa/xi-mac","description":null,"fork":true,"url":"https://api.github.com/repos/rkusa/xi-mac","forks_url":"https://api.github.com/repos/rkusa/xi-mac/forks","keys_url":"https://api.github.com/repos/rkusa/xi-mac/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rkusa/xi-mac/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rkusa/xi-mac/teams","hooks_url":"https://api.github.com/repos/rkusa/xi-mac/hooks","issue_events_url":"https://api.github.com/repos/rkusa/xi-mac/issues/events{/number}","events_url":"https://api.github.com/repos/rkusa/xi-mac/events","assignees_url":"https://api.github.com/repos/rkusa/xi-mac/assignees{/user}","branches_url":"https://api.github.com/repos/rkusa/xi-mac/branches{/branch}","tags_url":"https://api.github.com/repos/rkusa/xi-mac/tags","blobs_url":"https://api.github.com/repos/rkusa/xi-mac/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rkusa/xi-mac/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rkusa/xi-mac/git/refs{/sha}","trees_url":"https://api.github.com/repos/rkusa/xi-mac/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rkusa/xi-mac/statuses/{sha}","languages_url":"https://api.github.com/repos/rkusa/xi-mac/languages","stargazers_url":"https://api.github.com/repos/rkusa/xi-mac/stargazers","contributors_url":"https://api.github.com/repos/rkusa/xi-mac/contributors","subscribers_url":"https://api.github.com/repos/rkusa/xi-mac/subscribers","subscription_url":"https://api.github.com/repos/rkusa/xi-mac/subscription","commits_url":"https://api.github.com/repos/rkusa/xi-mac/commits{/sha}","git_commits_url":"https://api.github.com/repos/rkusa/xi-mac/git/commits{/sha}","comments_url":"https://api.github.com/repos/rkusa/xi-mac/comments{/number}","issue_comment_url":"https://api.github.com/repos/rkusa/xi-mac/issues/comments{/number}","contents_url":"https://api.github.com/repos/rkusa/xi-mac/contents/{+path}","compare_url":"https://api.github.com/repos/rkusa/xi-mac/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rkusa/xi-mac/merges","archive_url":"https://api.github.com/repos/rkusa/xi-mac/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rkusa/xi-mac/downloads","issues_url":"https://api.github.com/repos/rkusa/xi-mac/issues{/number}","pulls_url":"https://api.github.com/repos/rkusa/xi-mac/pulls{/number}","milestones_url":"https://api.github.com/repos/rkusa/xi-mac/milestones{/number}","notifications_url":"https://api.github.com/repos/rkusa/xi-mac/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rkusa/xi-mac/labels{/name}","releases_url":"https://api.github.com/repos/rkusa/xi-mac/releases{/id}","deployments_url":"https://api.github.com/repos/rkusa/xi-mac/deployments","created_at":"2017-04-21T11:05:38Z","updated_at":"2017-04-21T11:05:39Z","pushed_at":"2017-05-11T16:17:27Z","git_url":"git://github.com/rkusa/xi-mac.git","ssh_url":"git@github.com:rkusa/xi-mac.git","clone_url":"https://github.com/rkusa/xi-mac.git","svn_url":"https://github.com/rkusa/xi-mac","homepage":null,"size":1074,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"b2e542fa58fa0724b841a42d23ae6cfd90dafe12","user":{"login":"google","id":1342004,"avatar_url":"https://avatars2.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":78881023,"name":"xi-mac","full_name":"google/xi-mac","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars2.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/xi-mac","description":null,"fork":false,"url":"https://api.github.com/repos/google/xi-mac","forks_url":"https://api.github.com/repos/google/xi-mac/forks","keys_url":"https://api.github.com/repos/google/xi-mac/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/xi-mac/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/xi-mac/teams","hooks_url":"https://api.github.com/repos/google/xi-mac/hooks","issue_events_url":"https://api.github.com/repos/google/xi-mac/issues/events{/number}","events_url":"https://api.github.com/repos/google/xi-mac/events","assignees_url":"https://api.github.com/repos/google/xi-mac/assignees{/user}","branches_url":"https://api.github.com/repos/google/xi-mac/branches{/branch}","tags_url":"https://api.github.com/repos/google/xi-mac/tags","blobs_url":"https://api.github.com/repos/google/xi-mac/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/xi-mac/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/xi-mac/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/xi-mac/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/xi-mac/statuses/{sha}","languages_url":"https://api.github.com/repos/google/xi-mac/languages","stargazers_url":"https://api.github.com/repos/google/xi-mac/stargazers","contributors_url":"https://api.github.com/repos/google/xi-mac/contributors","subscribers_url":"https://api.github.com/repos/google/xi-mac/subscribers","subscription_url":"https://api.github.com/repos/google/xi-mac/subscription","commits_url":"https://api.github.com/repos/google/xi-mac/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/xi-mac/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/xi-mac/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/xi-mac/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/xi-mac/contents/{+path}","compare_url":"https://api.github.com/repos/google/xi-mac/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/xi-mac/merges","archive_url":"https://api.github.com/repos/google/xi-mac/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/xi-mac/downloads","issues_url":"https://api.github.com/repos/google/xi-mac/issues{/number}","pulls_url":"https://api.github.com/repos/google/xi-mac/pulls{/number}","milestones_url":"https://api.github.com/repos/google/xi-mac/milestones{/number}","notifications_url":"https://api.github.com/repos/google/xi-mac/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/xi-mac/labels{/name}","releases_url":"https://api.github.com/repos/google/xi-mac/releases{/id}","deployments_url":"https://api.github.com/repos/google/xi-mac/deployments","created_at":"2017-01-13T19:46:46Z","updated_at":"2017-05-12T02:53:34Z","pushed_at":"2017-05-12T01:53:00Z","git_url":"git://github.com/google/xi-mac.git","ssh_url":"git@github.com:google/xi-mac.git","clone_url":"https://github.com/google/xi-mac.git","svn_url":"https://github.com/google/xi-mac","homepage":null,"size":1030,"stargazers_count":378,"watchers_count":378,"language":"Swift","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":15,"forks":21,"open_issues":15,"watchers":378,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/xi-mac/pulls/32"},"html":{"href":"https://github.com/google/xi-mac/pull/32"},"issue":{"href":"https://api.github.com/repos/google/xi-mac/issues/32"},"comments":{"href":"https://api.github.com/repos/google/xi-mac/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/google/xi-mac/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/google/xi-mac/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/xi-mac/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/google/xi-mac/statuses/0d4ebf6032c0390dd779c7a3614d21081e7a84c9"}}}}
{"actor":{"display_login":"rkusa"}}