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

Add a setFont method to CodeArea #754

Closed
RohitAwate opened this issue Jun 21, 2018 · 7 comments
Closed

Add a setFont method to CodeArea #754

RohitAwate opened this issue Jun 21, 2018 · 7 comments

Comments

@RohitAwate
Copy link
Contributor

Desired Feature

A setFont() method for CodeArea would be really helpful. JavaFX's default TextArea also comes with it.

Current Workarounds

I'm using CodeArea for Everest and currently setting the font through CSS. However, I'm loading custom user settings from a file which include the font family and size. I tried setting these attributes with setStyle() but that didn't work. Looks like currently there's no way to set these values without adding a stylesheet. Hence, I've had to revoke this feature temporarily.

Implementation Costs

I haven't gone through the source but since this is already possible via CSS, I think the groundwork is there, so this shouldn't be too massive of a request.
I'm also okay with a workaround if you have one, but I think a text control should have a setFont method.

Also, I was hoping you could add Everest to 'Who uses RichTextFX?'.

Thanks! :)

@JordanMartinez
Copy link
Contributor

Also, I was hoping you could add Everest to 'Who uses RichTextFX?'.

Nice application! Usually, we just ask you to submit a PR that includes a link to it on the ReadMe.

I agree that this feature should be added. Would you be willing to do the work if I helped you do it?

@RohitAwate
Copy link
Contributor Author

RohitAwate commented Jun 22, 2018

Usually, we just ask you to submit a PR that includes a link to it on the ReadMe.

Oh, I thought I have to message you somehow. I'll do this. 👍

Would you be willing to do the work if I helped you do it?

Sure. I can certainly give it a shot. I hope its not too complex though.

EDIT: Unrelated to the issue but, I'm having a hard time parsing XML for Everest and I don't wish to invest too much time in regex. Is it cool if I use XMLEditorDemo?

@JordanMartinez
Copy link
Contributor

Unrelated to the issue but, I'm having a hard time parsing XML for Everest and I don't wish to invest too much time in regex. Is it cool if I use XMLEditorDemo?

This project is dual-licensed (as in, "choose which license you want to use") and that includes the demos. So, go for it as long as it abides by one of those licenses (probably the BSD-2)

Oh, I thought I have to message you somehow. I'll do this. 👍

Great!

Sure. I can certainly give it a shot. I hope its not too complex though.

It's really not. However, after thinking about it more, I'm not sure whether that would be desired/needed. If you did submit a PR, you'd need to..

It's this last part that is up for discussion. Assuming a developer other than you wants each text's font to be different, then whatever we change should not interfere with that. In other words, if a given text object is styled in such a way that it should be rendered in one font (i.e. Arial) that's different from the area's font (i.e. Times New Roman), I think the text should be rendered in Arial, not Times New Roman.

And it's this last part that makes me wonder whether such a PR is even necessary (or desirable). For example, although there is no "set font" method on the area, you could easily create one in your custom area. How? By defining a custom style type that merges the "style a text by style class" and "style a text by setting its properties" methodologies described in the wiki page on this topic. The following code is an example of how you could do that.

Given an immutable custom style object:

public class FontAndStyle {
    private final Font font;
    private final String styleClass;

   // and getters

    public FontAndStyle(Font f, String, s) {
        this.font = f;
        this.styleClass = s
    }

    // and corresponding style class setter
    public FontAndStyle setFont(Font f) { new FontAndStyle(f, styleClass); }
}

and a custom applyStyle in this method, which is what most use to create the Text object in the first place

(TextExt text, FontAndStyle s) -> {
    text.setStyleClass(s.getStyleClass());
    text.setFont(s.getFont());
}

and by using StyleSpans#mapStyles, you could remap all the styles' font to a new one using this method in you area:

public void setFont(Font f) {
    StyleSpans<FontAndStyle> spans = this.getStyleSpans();
    this.setStyleSpans(spans.mapStyles(s -> s.setFont(f));
}

The end result is that each text object that gets rendered would have the same font and you'd have an easy convenience method to do that.

@RohitAwate
Copy link
Contributor Author

This project is dual-licensed (as in, "choose which license you want to use") and that includes the demos. So, go for it as long as it abides by one of those licenses (probably the BSD-2)

Great! So is it enough if I include BSD-2 in the copyright header of my XML highlighter (with a link to the demo) along with my own Apache 2.0 since there are minor modifications to your demo?

I see your point regarding whether this method is really necessary and I agree that for StyledTextArea, the proposed method may be a problem. But I think it makes sense for CodeArea. I don't think anyone uses multiple fonts in their code editors. What do you think?

Also, thanks for the detailed guidelines for the PR and the workaround! 👍
They'll be really helpful whichever way we chose to go.

@JordanMartinez
Copy link
Contributor

Also, thanks for the detailed guidelines for the PR and the workaround! +1
They'll be really helpful whichever way we chose to go.

You're welcome!

Great! So is it enough if I include BSD-2 in the copyright header of my XML highlighter (with a link to the demo) along with my own Apache 2.0 since there are minor modifications to your demo?

Mm... I'm not going to answer that question since it implies legal advice ;-). I think the license tells you what you need to do. AFAIK, Apache 2.0 can "absorb" the BSD-2 according to this chart

But I think it makes sense for CodeArea. I don't think anyone uses multiple fonts in their code editors. What do you think?

But since CodeArea is a subclass of GenericStyledArea, the same issue would still arise. We'd still have to modify GenericStyledArea to allow CodeArea to do that. If you made your own custom CodeArea that specifies the S parameter of GenericStyledArea to the above code, then it'll still work as you'd like.

@RohitAwate
Copy link
Contributor Author

But since CodeArea is a subclass of GenericStyledArea, the same issue would still arise. We'd still have to modify GenericStyledArea to allow CodeArea to do that. If you made your own custom CodeArea that specifies the S parameter of GenericStyledArea to the above code, then it'll still work as you'd like.

I see. I've already subclassed CodeArea so I'll just follow your workaround.

Mm... I'm not going to answer that question since it implies legal advice ;-). I think the license tells you what you need to do. AFAIK, Apache 2.0 can "absorb" the BSD-2 according to this chart

Haha right. Everest is my first serious public project so this legal stuff is a bit confusing. I'll still include your license and a link since the demo saved a week of my work and works perfectly. The Java demo was also really helpful in writing my JSON highlighter.

Closing this.
This exchange was really informative. Thanks for your work! :)
Good luck.

@JordanMartinez
Copy link
Contributor

Glad to have helped and wish you well on your project!

If you ever want to hack away at RTFX and need a deeper understanding of it, see the wiki's home page, which lists various things to read for various levels of understanding

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