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

updated by GinforJM #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

GinforJM
Copy link

the issue 81 has been solved.
I will preprocess the background image and change it to be transparent.

the issue 81 has been solved.
I will preprocess the background image and change it to be transparent.
Copy link
Owner

@kennycason kennycason left a comment

Choose a reason for hiding this comment

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

@GinforJM 谢谢你支持KUMO!我评论了一些小的推荐和请求。

我觉得第一重要的应该是那个“sun.font.FontDesignMetrics”的class。因为这个class从sun(oracle)的package来的,所以好像不能用,因为有很大的可能别的JDK就没有这个package,所以就不能compile。我还没想到最好的办法解决这个。最坏情况是我们可以直接把那个class拷贝到KUMO里。我们先去研究一下。
如果还有什么不清楚的地方,马上跟我说,谢谢:)。

/**
* preprocess the image if the image is not
*/
//CS304 Issue link: https://github.com/kennycason/kumo/issues/81
Copy link
Owner

Choose a reason for hiding this comment

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

go ahead and remove the line 38 comments.

@Override
public void mask(final RectanglePixelCollidable background) {
Copy link
Owner

Choose a reason for hiding this comment

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

I intentionally want final on all variables and method parameters. It's considered best practice and most programming languages now include val/var types as first level types as well with preference on val, including new versions of Java.

import com.kennycason.kumo.collide.RectanglePixelCollidable;
import com.kennycason.kumo.image.CollisionRaster;

import sun.font.FontDesignMetrics;
Copy link
Owner

Choose a reason for hiding this comment

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

Can you find another way to implement this without using sun.* package. In general, usage of sun.* packages have been deprecated for some time if I recall correctly.

Copy link
Owner

Choose a reason for hiding this comment

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

https://stackoverflow.com/questions/8565708/what-is-inside-com-sun-package

Check out the top rated answer for more details:

Please note that the com.sun.* package should not be confused with sun.* package which are the internal classes behind Oracle JRE which you should absolutely not import/use in your code as it would make your code tight coupled to the JRE make/version. Not using sun.* package at all enables you to run your code on all other JRE implementations (OpenJDK, GCJ, etc).

Copy link
Owner

Choose a reason for hiding this comment

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

I'll also research a better alternative. If you can't find another alternative, feel free to literally just copy the implementation into Kumo if it is small enough.

Copy link
Owner

Choose a reason for hiding this comment

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

@GinforJM Hi! I just wanted to check back in and see if you found an alternative to sun.font.FontDesignMetrics.
Thanks!

* @param size the size of each character in the string
*/
//CS304 Issue link: https://github.com/kennycason/kumo/issues/70
public PixelBoundryBackground(String example , int size){
Copy link
Owner

Choose a reason for hiding this comment

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

final variables/parameters. (and space between ) {)

* @param content the content of the input string
* @return return a width of a word
*/
//CS304 Issue link: https://github.com/kennycason/kumo/issues/70
Copy link
Owner

Choose a reason for hiding this comment

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

remove comment on line 137.

graphics.drawString(example, 0, metrics.getAscent());//图片上写文字
graphics.dispose();
BufferedImage b = preprocess(bufferedImage,5);
// changed
Copy link
Owner

Choose a reason for hiding this comment

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

delete this comment on line 125.

*/
//CS304 Issue link: https://github.com/kennycason/kumo/issues/70
public PixelBoundryBackground(String example , int size){
Font font = new Font("微软雅黑", Font.BOLD, size);
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should make this:

  1. rename example to text

  2. final Font font = new Font(settings.getFontName(), settings.getFontWeight(), settings.getFontSize());
    This way we can configure the font and we should also come up with a better default font. I don't think most people are familiar with "微软雅黑". Maybe Calibri for now, or something else more common.
    Then where you use example below, you can also just say settings.getText()

you could then construct with PixelBoundryBackground(final PixelBoundryBackgroundSettings settings)

}
BufferedImage bi = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_4BYTE_ABGR);//Create a new type that supports transparent BufferedImage
for(int i = 0; i < imgWidth; ++i)//Copy the contents of the original image to the new image, and set the background to transparent
{
Copy link
Owner

Choose a reason for hiding this comment

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

put the brackets on the same same line as for, also note spacing/finals.

for (int i = 0; i < imgWidth; ++i) {

Apply to all below code.

int imgWidth = srcImage.getWidth();
int c = srcImage.getRGB(3, 3);
//防止越位
if (alpha < 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

I feel we should set alpha value between [0.0, 1.0], and if the users sets it over < 0.0 or > 1.0, throw an exception since it's bad input. Then later you can more easily do: rgb = ((alpha * 255).toInt() << 24) | (rgb & 0x00ffffff); below.

@GinforJM
Copy link
Author

GinforJM commented Jun 23, 2020 via email

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