dankito / RichTextEditor

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

How do I get rid of other fonts or add my own #21

Closed ubarua123 closed 5 years ago

ubarua123 commented 5 years ago

Can I remove some of the font family options? Or where can I find that list? For a font it says "Coming soon" . I would like to remove that. Is it possible?

ubarua123 commented 5 years ago

Also, is it possible to get a "text only" version after the user has entered or do I have to use an html parser like jsoup? Reason being, after the user has typed, I may want to integrate a grammar checker. But that tool will not understand HTML. So it'll need a text only version output. Sorry for so many questions!

dankito commented 5 years ago

Your questions are highly welcome.

First question: Fonts The according commands are SetFontNameCommand and SetFontNameWithPreviewCommand. Both use FontNameUtils that loads via SystemFontsParser all fonts available on system. (SystemFontsParser is a private field in FontNameUtils, my bad, sorry.) So you can either extend one of the two commands and use that one, or pass them a class derived from FontNameUtils. In both ways you should be able to customize the displayed font families. Does that help you?

Second question: Plain text Right, parsing the html with jsoup is also what i do for getting the plain text. Do you think i should provide a method getHtmlAsPlainText() or something like that to make it more handy for you?

Feel free to give me a pull request when you're done with your grammar checker, i'd love to integrate it into RichTextEditor.

ubarua123 commented 5 years ago
  1. Ok got it. I guess I'll have to pass on that coz I don't know kotlin that well yet. Lets see how I do it then.
  2. I think it'll be great if you provide it because otherwise I'll also end up doing the same and since you're using jsoup already, why do double effort. It'll be great then.

Abouthe grammar checker, yeah I'll first do some research and see which ones fit well then I'll get in touch with you. :)

dankito commented 5 years ago
  1. As Kotlin compiles to Java byte code, you can use all the Kotlin classes as if they were Java classes, e. g. derive from it:
public class CustomizedSetFontNameWithPreviewCommand extends SetFontNameWithPreviewCommand {

    @NotNull
    @Override
    public List<CharSequence> initValuesDisplayTexts() {
        List<CharSequence> systemFonts = super.initValuesDisplayTexts();

        // customize font list here
        List<CharSequence> yourFonts = new ArrayList<>(systemFonts);

        return yourFonts;
    }

}

But i saw that by far not all command classes were overridable (Kotlin makes classes final by default). I changed that now and will be part of the upcoming 2.0.9 release. If there are any issues calling the Kotlin code, e.g. private fields, final classes, ..., let me know, then i change that for you.

  1. Sorry, i was wrong. I used jsoup in my other project which uses RichTextEditor as a dependency, not in RichTextEditor itself. As i don't want to add another dependency to RichTextEditor if it's not absolutely necessary (i think for a library it already has too much dependencies), would it be OK if you convert the html to plain text in your project? And maybe converting html to plain text isn't even necessary for you:

Grammar checker: As RichTextEditor is using JavaScript under the hood (see rich_text_editor.js), may using a JavaScript grammar / spell checker already fits your needs.