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

同问,英文的文章,如何可以排版正确呢? #95

Open
luotext opened this issue Jul 5, 2020 · 3 comments
Open

同问,英文的文章,如何可以排版正确呢? #95

luotext opened this issue Jul 5, 2020 · 3 comments

Comments

@luotext
Copy link

luotext commented Jul 5, 2020

就是英文是按照单词来解释的,但是按照中文来计算,那么单词就被切割掉了,最后一行的单词就变得不完整了,并延申到第二行去了

@luotext
Copy link
Author

luotext commented Jul 7, 2020

就是英文是按照单词来解释的,但是按照中文来计算,那么单词就被切割掉了,最后一行的单词就变得不完整了,并延申到第二行去了

所以我加了个判断
private oolean isTrue(String line) {
return !line.endsWith(" ") &&
!line.endsWith(",") &&
!line.endsWith(".") &&
!line.endsWith("-") &&
!line.equals(""");
}
其实也就是在当前要绘制的行末尾判断是否以上结尾,来达到判断是否单词被切割了,但是这样判断符号的情况,感觉并不友好。

@luotext
Copy link
Author

luotext commented Jul 7, 2020

就是英文是按照单词来解释的,但是按照中文来计算,那么单词就被切割掉了,最后一行的单词就变得不完整了,并延申到第二行去了

所以我加了个判断
private oolean isTrue(String line) {
return !line.endsWith(" ") &&
!line.endsWith(",") &&
!line.endsWith(".") &&
!line.endsWith("-") &&
!line.equals(""");
}
其实也就是在当前要绘制的行末尾判断是否以上结尾,来达到判断是否单词被切割了,但是这样判断符号的情况,感觉并不友好。

如果是被切割了,直接按照最后一个空格来截取,结束这一行。str = str.substring(0, str.lastIndexOf(" ") + 1);

@lingyun14
Copy link

//解决行末单词拆分的问题
if(paragraph.length() > wordCount && paragraph.substring(0, wordCount).contains(" ")){
char start = paragraph.charAt(wordCount);
char end = paragraph.charAt(wordCount - 1);
if(start != ' ' && end != ' '){//一个单词被断开的情况
int index = paragraph.lastIndexOf(' ', wordCount);
if(index > -1){
wordCount = index + 1;
}
}
}
subStr = paragraph.substring(0, wordCount);

我是在loadPages中将wordCount重新计算的

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