Skip to content

Simplify MarkdownLineHeightSpan logic #522

Open

Description

@tomekzaw

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.

Activity

  1. changed the title [-]Eliminate weird logic related to `MarkdownLineHeightSpan`[/-] [+]Simplfy `MarkdownLineHeightSpan` logic[/+] on Oct 18, 2024
  2. changed the title [-]Simplfy `MarkdownLineHeightSpan` logic[/-] [+]Simplify `MarkdownLineHeightSpan` logic[/+] on Oct 18, 2024
  3. tomekzaw commented on Nov 4, 2024

    @tomekzaw
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions