Skip to content

Commit

Permalink
Fix text input for non-latin characters
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Jan 30, 2022
1 parent b5d9161 commit 1f0251d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Zavala.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
51028CD525F3159A00B50B71 /* UIColor+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51028CD425F3159A00B50B71 /* UIColor+.swift */; };
510471BB271940E5001DEFD5 /* MoveRowsIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510471BA271940E5001DEFD5 /* MoveRowsIntentHandler.swift */; };
510471BD2719AEFA001DEFD5 /* RemoveRowsIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510471BC2719AEFA001DEFD5 /* RemoveRowsIntentHandler.swift */; };
51077C5227A752DF000C71DB /* UIFont+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51077C5127A752DF000C71DB /* UIFont+.swift */; };
5113B08D260C1F1700DBD11B /* OutlineFontCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5113B08C260C1F1700DBD11B /* OutlineFontCache.swift */; };
5113B092260E45B400DBD11B /* SettingsFontViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5113B091260E45B400DBD11B /* SettingsFontViewController.swift */; };
5113B095260E638400DBD11B /* SettingsFontConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5113B094260E638400DBD11B /* SettingsFontConfigViewController.swift */; };
Expand Down Expand Up @@ -257,6 +258,7 @@
51028CD425F3159A00B50B71 /* UIColor+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+.swift"; sourceTree = "<group>"; };
510471BA271940E5001DEFD5 /* MoveRowsIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveRowsIntentHandler.swift; sourceTree = "<group>"; };
510471BC2719AEFA001DEFD5 /* RemoveRowsIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoveRowsIntentHandler.swift; sourceTree = "<group>"; };
51077C5127A752DF000C71DB /* UIFont+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+.swift"; sourceTree = "<group>"; };
5113B08C260C1F1700DBD11B /* OutlineFontCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineFontCache.swift; sourceTree = "<group>"; };
5113B091260E45B400DBD11B /* SettingsFontViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsFontViewController.swift; sourceTree = "<group>"; };
5113B094260E638400DBD11B /* SettingsFontConfigViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsFontConfigViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -532,6 +534,7 @@
517342F125EC2C690012EB20 /* UIActivityViewController+.swift */,
5169928925AE4F5C00760C9D /* UICollectionView+.swift */,
51028CD425F3159A00B50B71 /* UIColor+.swift */,
51077C5127A752DF000C71DB /* UIFont+.swift */,
5173B405268BBD4200687117 /* UIImage+.swift */,
51DEE82126FE37F9006DAA56 /* UIPrintPageRenderer+.swift */,
514BB9E6255B609600C8DBDF /* UIStoryboard+.swift */,
Expand Down Expand Up @@ -1159,6 +1162,7 @@
51F36C5826FAB5C90075A273 /* ExportMarkdownDocActivity.swift in Sources */,
51DEE82626FE87CD006DAA56 /* ExportPDFListActivity.swift in Sources */,
5147D0B525CB95B4004673C3 /* DocumentsViewController+Drag.swift in Sources */,
51077C5227A752DF000C71DB /* UIFont+.swift in Sources */,
51D977FA257A2E4F00D98490 /* EditorRowPreviewParameters.swift in Sources */,
5191850927137DFD00B7E177 /* GetCurrentTagsIntentHandler.swift in Sources */,
517AF69C25E0862E0044DBAB /* AppDefaults.swift in Sources */,
Expand Down
7 changes: 6 additions & 1 deletion Zavala/Editor/Row/EditorRowTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ extension EditorRowTextView: NSTextStorageDelegate {
} else {
let ufd = oldFont.fontDescriptor.withFamily(newFont.familyName).withSymbolicTraits(oldFont.fontDescriptor.symbolicTraits) ?? oldFont.fontDescriptor.withFamily(newFont.familyName)
let newFont = UIFont(descriptor: ufd, size: newFont.pointSize)
newAttributes[key] = newFont

if newFont.isValidFor(value: charsInRange) {
newAttributes[key] = newFont
} else {
newAttributes[key] = oldFont
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions Zavala/Utility/UIFont+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// UIFont+.swift
// Zavala
//
// Created by Maurice Parker on 1/30/22.
//

import UIKit

extension UIFont {

func isValidFor(value: String) -> Bool {
var code_point: [UniChar] = Array(value.utf16)
var glyphs: [CGGlyph] = [0]
return CTFontGetGlyphsForCharacters(self as CTFont, &code_point, &glyphs, glyphs.count)
}

}

0 comments on commit 1f0251d

Please sign in to comment.