Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing text increases font size #13

Open
TheGeekPharaoh opened this issue Apr 24, 2019 · 6 comments
Open

Editing text increases font size #13

TheGeekPharaoh opened this issue Apr 24, 2019 · 6 comments

Comments

@TheGeekPharaoh
Copy link

I've run into an issue where if i create HTML text, save it (somewhere), then use RichTextEditor to edit the same text, the font size is increased. Example...

  1. The original text I enter is "This is my basic entry", with the font set to Arial 12.0. The result:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta http-equiv="Content-Style-Type" content="text/css">
      <title></title>
      <meta name="Generator" content="Cocoa HTML Writer">
      <style type="text/css">np.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Arial}nspan.s1 {font-family: 'Arial'; font-weight: normal; font-style: normal; font-size: 12.00pt}</style>
   </head>
   <body>
      <p class="p1"><span class="s1">This is my basic entry<span class="Apple-converted-space"> </span></span></p>
   </body>
</html>
  1. I save this text off, then go to edit it by calling richTextEditor?.setHtmlString()

  2. Upon saving, my font size is automatically increased (with no interaction from me) to Arial 16.0. Result:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta http-equiv="Content-Style-Type" content="text/css">
      <title></title>
      <meta name="Generator" content="Cocoa HTML Writer">
      <style type="text/css">np.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 16.0px Arial; color: #000000; -webkit-text-stroke: #000000}nspan.s1 {font-family: 'Arial'; font-weight: normal; font-style: normal; font-size: 16.00pt; font-kerning: none}</style>
   </head>
   <body>
      <p class="p1"><span class="s1">This is my basic entry<span class="Apple-converted-space"> </span></span></p>
   </body>
</html>
  1. If I repeat this edit on the text from (3), the font size is again increased to Arial 21.3. Result:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta http-equiv="Content-Style-Type" content="text/css">
      <title></title>
      <meta name="Generator" content="Cocoa HTML Writer">
      <style type="text/css">np.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 26.0px; font: 21.3px Arial; color: #000000; -webkit-text-stroke: #000000}nspan.s1 {font-family: 'Arial'; font-weight: normal; font-style: normal; font-size: 21.33pt; font-kerning: none}</style>
   </head>
   <body>
      <p class="p1"><span class="s1">This is my basic entry<span class="Apple-converted-space"> </span></span></p>
   </body>
</html>

Please advise. Thanks!

@Deadpikle
Copy link
Owner

Greetings!

How are you saving the text? What function(s) are you calling to convert the NSAttributedString to HTML? Any chance you could plop your functions here for load and save?

@TheGeekPharaoh
Copy link
Author

TheGeekPharaoh commented Apr 25, 2019 via email

@Deadpikle
Copy link
Owner

Hi again,

Sorry for your wait.

I am able to replicate the issue you're facing; however, I don't think it's unique to this RTE. All the code for loading and saving is calling native iOS stuff...hhmmmm....

The best I can figure out right now is that the HTML for px is being converted to pt (times 96/72) -- 12x96/72 = 16, which is what you're seeing. So, both the saving and loading appear to be messing up somehow.

It looks as though someone has had this issue before. Please see: https://stackoverflow.com/q/28441486/3938401 -- thus, it looks like this is an iOS/Apple issue. 😢

The reason I never ran into this myself is that I use DTCoreText to do all my HTML loading and saving (on both iOS and Mac). I recall usually using DTUseiOS6Attributes when loading/saving HTML, but I don't know if that's needed on newer versions of iOS.

@TheGeekPharaoh
Copy link
Author

Thanks for your quick response! I'll be sure to check out DTCoreText. Any examples or advice for making use of it?

@TheGeekPharaoh
Copy link
Author

For what it's worth, I took a stab at incorporating the answer from the Stackoverflow link you provided and it worked like a charm! I simply overrode the [RichTextEditor attributedStringFromHTMLString] method with the answer. I can try and clean it up a bit and submit a pull request for you.

@Deadpikle
Copy link
Owner

Hi, I'm sorry for my lack of response. I'm not dead, just very busy. 😅

I'm glad the SO link answer worked!! Very good to hear. Will keep this issue open for visibility for future users.

I'm open to PR's, sure. If you do one, please make the behavior opt-out so that folks can turn it off as they have need. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants