dankito / RichTextEditor

Rich text WYSIWYG editor for Android and JavaFX
Apache License 2.0
92 stars 36 forks source link

How can I apply sans-serif as default font on screen load ? #23

Closed tised closed 5 years ago

tised commented 5 years ago

So the thing is, I want to set as "default" font for input - sans-serif. I found method editor.setEditorFontFamily("sans-serif") but it sets only for preview mode (as I understand) After saving note, <font> tag not included into HTML

Also, I tried to use editor.javaScriptExecutor.executeEditorJavaScriptFunction("setFontName('sans-serif')") on screen load, but sometimes it works, sometimes not My guess is that pointer goes outside of tag on screen open, or something like this Can you help me with that ?

P.S. when I selecting font from SetFontNameCommand all works perfectly, but I do not understand why editor.javaScriptExecutor.executeEditorJavaScriptFunction("setFontName('sans-serif')") not working then

tised commented 5 years ago

Just found in sources private fun editorLoaded(context: Context) { isLoaded = true

    paddingToSetOnStart?.let {
        setPadding(it.left, it.top, it.right, it.bottom)
        paddingToSetOnStart = null
    }

    (context as? Activity)?.runOnUiThread {
        setEditorFontFamily("serif")
    }
}

I think it would be better if you will move setEditorFontFamily("serif") to a variable which can be changed over attributes while RichTextEditor initializes, and by default it will have "serif"

dankito commented 5 years ago

You're right in both regards: There should be a way to set default font family and - even though not mentioned directly - editorLoaded() method should be overrideable.

The reason why it sometimes works and sometimes not should be a classical race condition: Sometimes the async editor loading is faster (then it works), sometimes your method call (then it doesn't work).

As I haven't found a senseful way how to set default font family on editor (if you know any, please let me know), I did two things:

Both changes are on branch release/2.0.x (https://github.com/dankito/RichTextEditor/blob/release/2.0.x/RichTextEditorAndroid/src/main/kotlin/net/dankito/richtexteditor/android/RichTextEditor.kt).

If you think they are senseful I can release version 2.10 so that they are publicly available.

tised commented 5 years ago

I think your solution is pretty good! Release 2.10, please

dankito commented 5 years ago

Just released version 2.0.10. Should be visible at Maven Central within two hours.

Just let me know if suits your needs so that I can close this issue.

tised commented 5 years ago

Hello! Yes, seems it working, now I able to set "sans-serif" as default