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

Support non-monospace/monospace font rendering #207

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

BeichenDream
Copy link

Fix bug
issue

@BeichenDream
Copy link
Author

Now it supports the rendering of non-monospaced fonts

fix

@segrey
Copy link
Contributor

segrey commented Jul 2, 2021

@BeichenDream Seems most changes in TerminalPanel.java are caused by different formatting options (4 spaces instead of 2, etc.) Could you please adjust your formatting options to keep meaningful changes only?

@BeichenDream
Copy link
Author

@BeichenDream Seems most changes in TerminalPanel.java are caused by different formatting options (4 spaces instead of 2, etc.) Could you please adjust your formatting options to keep meaningful changes only?

Do you mean code style?

@segrey
Copy link
Contributor

segrey commented Jul 2, 2021

Yes, code style

fix code style
@BeichenDream
Copy link
Author

Yes, code style

Now that the code has been fixed, you can test it

@segrey
Copy link
Contributor

segrey commented Jul 2, 2021

@BeichenDream Unfortunately, the diff is still large (3216 lines). Can you please checkout the original TerminalPanel, apply your changes and push it without reformatting the whole file?

fix code style
@BeichenDream
Copy link
Author

Alright, I have manually fixed the code style now. Now you can test the code.

@@ -1079,11 +1120,11 @@ void drawCursor(String c, Graphics2D gfx, TextStyle style) {
}

CharBuffer buf = new CharBuffer(c);
int xCoord = x * myCharSize.width + getInsetX();
int xCoord = computexCoord(x, y) + getInsetX();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it will cost some performance, because now painting (height,width) panel would require approximately (height * width * width) / 2 calls of gfx.getFontMetrics(font).charWidth(<char>).

Copy link
Author

@BeichenDream BeichenDream Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a must for non-monospaced fonts;

There is another point that can be cached after rendering. If Terminal does not receive keyboard messages or mouse messages or the size of the window changes, you can directly return the results of the last rendering. This can solve the performance problem.

For me, the rendering of non-monospaced fonts is necessary because it is impossible for our program to carry font files of dozens of megabytes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can build jediterm.jar from your fork and use it as a workaround. When proper support for non-monospaced is added, you can remove your fork. Will it work for you?

Copy link
Author

@BeichenDream BeichenDream Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can build jediterm.jar from your fork and use it as a workaround. When proper support for non-monospaced is added, you can remove your fork. Will it work for you?

I have seen a large number of non-monospaced fonts rendering issues in issues. If you don’t solve it, I think you should understand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not sure I understand: if your software would use jediterm.jar built from your fork, it would solve non-monospaced fonts rendering issues for your users. Right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this change, fixing non-monospaced fonts rendering issues as it was suggested in this PR would lead to degraded performance for all fonts. I agree that non-monospaced fonts rendering issues should be fixed, but probably the fix should be more elaborate to not degrade performance for monospaced fonts. No particular plans, but I'll think about it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this change, fixing non-monospaced fonts rendering issues as it was suggested in this PR would lead to degraded performance for all fonts. I agree that non-monospaced fonts rendering issues should be fixed, but probably the fix should be more elaborate to not degrade performance for monospaced fonts. No particular plans, but I'll think about it.

Please do not close this PR. I should have time to fix performance issues in the next few months. Add double buffering and rendering cache to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let's keep it open. Not sure double buffering would help here. It seems to me that it's more about improving algorithm of calculating x-position of a cell.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimal calculation of X coordinate algorithm
Now it only accounts for 3.6% of the CPU in the entire drawing cycle

ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm has been optimized and now only takes up very little CPU

@segrey
Copy link
Contributor

segrey commented Jul 2, 2021

Thanks, I see your idea. I think fixing it for non-monospaced fonts shouldn't degrade performance for monospaced fonts.

@BeichenDream
Copy link
Author

Thanks, I see your idea. I think fixing it for non-monospaced fonts shouldn't degrade performance for monospaced fonts.

Yes, this is a must for non-monospaced fonts;

There is another point that can be cached after rendering. If Terminal does not receive keyboard messages or mouse messages or the size of the window changes, you can directly return the results of the last rendering. This can solve the performance problem.

For me, the rendering of non-monospaced fonts is necessary because it is impossible for our program to carry font files of dozens of megabytes.

You can also create a method in the object TerminalPanel that indicates whether to perform non-monospace font rendering

Optimal calculation of X coordinate algorithm
Now it only accounts for 3.6% of the CPU in the entire drawing cycle
@BeichenDream
Copy link
Author

I think you can merge branches now

@segrey
Copy link
Contributor

segrey commented Jul 2, 2021

I've reviewed the lastest commit (99db2b4) and there are still (height * width * width) / 2 calls of gfx.getFontMetrics(font).charWidth(<char>).

Copy link
Author

@BeichenDream BeichenDream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the lastest commit (99db2b4) and there are still (height * width * width) / 2 calls of gfx.getFontMetrics(font).charWidth(<char>).

I've reviewed the lastest commit (99db2b4) and there are still (height * width * width) / 2 calls of gfx.getFontMetrics(font).charWidth(<char>).

Yes, this is indispensable at the moment, but it only occupies 3% of the cpu of the drawing cycle. I think it’s good for not being able to render non-monospaced fonts.

@@ -1079,11 +1120,11 @@ void drawCursor(String c, Graphics2D gfx, TextStyle style) {
}

CharBuffer buf = new CharBuffer(c);
int xCoord = x * myCharSize.width + getInsetX();
int xCoord = computexCoord(x, y) + getInsetX();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimal calculation of X coordinate algorithm
Now it only accounts for 3.6% of the CPU in the entire drawing cycle

ok

@@ -1079,11 +1120,11 @@ void drawCursor(String c, Graphics2D gfx, TextStyle style) {
}

CharBuffer buf = new CharBuffer(c);
int xCoord = x * myCharSize.width + getInsetX();
int xCoord = computexCoord(x, y) + getInsetX();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm has been optimized and now only takes up very little CPU

@segrey
Copy link
Contributor

segrey commented Jul 2, 2021

3.6% is not much indeed, however, it'd be great to have 0% for monospaced fonts (if that's possible).
Thanks for your work, having it as a base, I'll improve it further in a few next weeks.

@BeichenDream
Copy link
Author

3.6% is not much indeed, however, it'd be great to have 0% for monospaced fonts (if that's possible).
Thanks for your work, having it as a base, I'll improve it further in a few next weeks.

I think we should not spend time on this 3.6% trivial matter. I use jvisualvm to analyze the program and found that most of the time and the cpu are executing the sun.java2d.SunGraphics2D.drawChars() method, so we currently optimize the program the most A good way is to increase the cache to reduce painting

@BeichenDream
Copy link
Author

In fact, we have now removed the calculation of wide characters, so it is faster than the original program.

Fix the pull-up progress bar cannot be rendered, reduce useless code calculations
@BeichenDream
Copy link
Author

Fix the pull-up progress bar cannot be rendered, reduce useless code calculations

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

Successfully merging this pull request may close these issues.

2 participants