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

Simplify MarkdownLineHeightSpan logic #522

Open
tomekzaw opened this issue Oct 18, 2024 · 1 comment · May be fixed by #535
Open

Simplify MarkdownLineHeightSpan logic #522

tomekzaw opened this issue Oct 18, 2024 · 1 comment · May be fixed by #535
Labels
enhancement New feature or request

Comments

@tomekzaw
Copy link
Collaborator

The current implementation of MarkdownLineHeightSpan is a bit tricky:

public class MarkdownLineHeightSpan implements MarkdownSpan, LineHeightSpan {
private final float mLineHeight;
public MarkdownLineHeightSpan(float lineHeight) {
mLineHeight = lineHeight;
}
@Override
public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int lineHeight, Paint.FontMetricsInt fm) {
fm.top -= mLineHeight / 4;
fm.ascent -= mLineHeight / 4;
}
}

Also, we need to obtain information about existing spans before applying MarkdownLineHeightSpan:

case "h1":
setSpan(ssb, new MarkdownBoldSpan(), start, end);
CustomLineHeightSpan[] spans = ssb.getSpans(0, ssb.length(), CustomLineHeightSpan.class);
if (spans.length >= 1) {
int lineHeight = spans[0].getLineHeight();
setSpan(ssb, new MarkdownLineHeightSpan(lineHeight * 1.5f), start, end);
}
// NOTE: size span must be set after line height span to avoid height jumps
setSpan(ssb, new MarkdownFontSizeSpan(mMarkdownStyle.getH1FontSize()), start, end);

The objective of this task is to eliminate division by 4 as well as calling .getSpans() method if needed.

@tomekzaw tomekzaw added the enhancement New feature or request label Oct 18, 2024
@tomekzaw tomekzaw changed the title Eliminate weird logic related to MarkdownLineHeightSpan Simplfy MarkdownLineHeightSpan logic Oct 18, 2024
@tomekzaw tomekzaw changed the title Simplfy MarkdownLineHeightSpan logic Simplify MarkdownLineHeightSpan logic Oct 18, 2024
@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 4, 2024

Proposal: Add h1.lineHeight to markdownStyle.

If style.lineHeight is undefined and markdownStyle.h1.lineHeight is undefined, we don't set CustomLineHeightSpan for headings (the line height is calculated automatically by Android).

If style.lineHeight is defined and markdownStyle.h1.lineHeight is undefined, we don't set CustomLineHeightSpan for headings (React Native applies CustomLineHeightSpan for whole text).

If markdownStyle.h1.lineHeight is defined, we set CustomLineHeightSpan for headings.

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

Successfully merging a pull request may close this issue.

1 participant