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

标题 Small caps 的样式未适配 #321

Closed
timelic opened this issue Dec 23, 2024 · 4 comments
Closed

标题 Small caps 的样式未适配 #321

timelic opened this issue Dec 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@timelic
Copy link
Contributor

timelic commented Dec 23, 2024

问题描述

截屏2024-12-23 10 53 59

对于这种 Small caps 的标题字号,应该参考第一个字母而非后续字母。判定条件应该是段落字体本身较大,且段落内有多个较为突出的首字母。

# converter.py
if not cur_v:                                               # 文字入栈
    if (                                                    # 根据当前字符修正段落属性
        child.size > pstk[-1].size / 0.79                   # 1. 当前字符显著比段落字体大
        or len(sstk[-1].strip()) == 1                       # 2. 当前字符为段落第二个文字(考虑首字母放大的情况)
    ) and child.get_text() != " ":                          # 3. 当前字符不是空格
        pstk[-1].y -= child.size - pstk[-1].size            # 修正段落初始纵坐标,假设两个不同大小字符的上边界对齐
        pstk[-1].size = child.size
    sstk[-1] += child.get_text()

测试文档

Important

请提供用于复现测试的 PDF 文档

https://openreview.net/pdf?id=u1cQYxRI1H

@Byaidu
Copy link
Owner

Byaidu commented Dec 23, 2024

有一种类似的情况是这样,也是第一个字母比第二个字母大 #86

想要区分两者需要额外的工作,而且启发式方法不一定准确

@timelic
Copy link
Contributor Author

timelic commented Dec 23, 2024

@Byaidu 首字母下沉和small caps确实容易造成混淆,但是并非无法区分。关键是首字母下沉只会有一次,而small caps会有多个较大的首字母。

@Byaidu
Copy link
Owner

Byaidu commented Dec 23, 2024

想了一下,我们可能不需要在状态转移时维护“出现了几个突出的首字母”

我们可以直接把代码里的规则1阈值去掉,改成child.size > pstk[-1].size就可以了,这样第二次突出大写出现的时候就会自动修正

至于当初为啥写的0.79好像记不太清了,可能是历史遗留(x

@timelic
Copy link
Contributor Author

timelic commented Dec 23, 2024

想了一下,我们可能不需要在状态转移时维护“出现了几个突出的首字母”

我们可以直接把代码里的规则1阈值去掉,改成child.size > pstk[-1].size就可以了,这样第二次突出大写出现的时候就会自动修正

至于当初为啥写的0.79好像记不太清了,可能是历史遗留(x

是的,这似乎非常巧妙!

@Byaidu Byaidu added the enhancement New feature or request label Dec 23, 2024
@Byaidu Byaidu closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants