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

Line Height is not calculating based on font size. #28

Closed
ritheshSalyan opened this issue Feb 18, 2021 · 36 comments
Closed

Line Height is not calculating based on font size. #28

ritheshSalyan opened this issue Feb 18, 2021 · 36 comments

Comments

@ritheshSalyan
Copy link

unnamed

when we have a large font size line-height has some problem.

@singerdmx
Copy link
Owner

Oh true if you have custom style

@singerdmx
Copy link
Owner

I think a good solution is to allow passing both custom style and its corresponding line height.
The change should be easy. I can point you where the code is after you finish the other issue.

@ritheshSalyan
Copy link
Author

ritheshSalyan commented Feb 18, 2021

this was from your example. i just added following line for that

 QuillEditor(
    //Rest of parameter 
   sizeHuge: TextStyle(fontSize:64.0)
)

@singerdmx
Copy link
Owner

Our current code does not support passing line height yet. Also line height should be optional.

@singerdmx
Copy link
Owner

Currently in a block each line is given the same height. Huge size is an attribute of text span.
What is your expectation? Do you want the line containing Huge size to have a different height?

@ritheshSalyan
Copy link
Author

yes. line-height should be equal to the biggest element in that line. as shown below

image

@singerdmx
Copy link
Owner

Ok this is more complicated than I thought.
We can further discuss this after finishing the first issue.

@ritheshSalyan
Copy link
Author

Flutters default rich text rendering has this.

@singerdmx
Copy link
Owner

image

One TextLine can contain multiple TextSpan and one of the TextSpan may have sizeHuge

@singerdmx
Copy link
Owner

Currently we use RichText for the whole TextLine.
Your need is asking it to be rendered per TextSpan.
Basically every TextSpan is one RichText

@ritheshSalyan
Copy link
Author

yes.

@ArjanAswal
Copy link
Collaborator

this was from your example. i just added following line for that

 QuillEditor(
    //Rest of parameter 
   sizeHuge: TextStyle(fontSize:64.0)
)

@ritheshSalyan I don't think there is a sizeHuge parameter anywhere in QuillEditor. Are you talking about H1?
In that case, you can pass custom line height.

@singerdmx
Copy link
Owner

singerdmx commented Feb 19, 2021

this was from your example. i just added following line for that

 QuillEditor(
    //Rest of parameter 
   sizeHuge: TextStyle(fontSize:64.0)
)

@ritheshSalyan I don't think there is a sizeHuge parameter anywhere in QuillEditor. Are you talking about H1?
In that case, you can pass custom line height.

image

This is quilljs on web, the generated delta has

"attributes": {
         "size": "huge"
      }

You can play on https://bulletjournal.us/collab/?uid=W4LOcDQo

@singerdmx
Copy link
Owner

You can play on https://bulletjournal.us/collab/?uid=W4LOcDQo

@ArjanAswal
Copy link
Collaborator

ArjanAswal commented Feb 19, 2021

this was from your example. i just added following line for that

 QuillEditor(
    //Rest of parameter 
   sizeHuge: TextStyle(fontSize:64.0)
)

@ritheshSalyan I don't think there is a sizeHuge parameter anywhere in QuillEditor. Are you talking about H1?
In that case, you can pass custom line height.

image

This is quilljs on web, the generated delta has

"attributes": {
         "size": "huge"
      }

Oh I see.
This is not on mobile right?
Also, can we instead pass custom font sizes instead of these 3 options only? It is possible and easy to implement. And we can also pass line height along with that.

Custom font-family can also be passed by the way.

@singerdmx
Copy link
Owner

Oh I see.
This is not on mobile right?
Also, can we instead pass custom font sizes instead of these 3 options only? It is possible and easy to implement. And we can also pass line height along with that.

Custom font-family can also be passed by the way.

Yes, not on mobile.
Custom font size is what this change is about - support double
Custom font-family should be already supported since it is string

@singerdmx
Copy link
Owner

Currently we use RichText for the whole TextLine.
Your need is asking it to be rendered per TextSpan.
Basically every TextSpan is one RichText

Custom Line height is a much tougher problem.
It is actually custom text span height.
Our concept of "Line" in code is different actually - it is continuous text span

@ArjanAswal
Copy link
Collaborator

You can play on https://bulletjournal.us/collab/?uid=W4LOcDQo

Just used this...
Found a bug.
Opening a new issue.

@ritheshSalyan
Copy link
Author

I found solution for this.
i replaced this

 RichText child = RichText(
      text: _buildTextSpan(context),
      textAlign: textAlign,
      textDirection: textDirection,
      strutStyle: strutStyle,
      textScaleFactor: MediaQuery.textScaleFactorOf(context),
    );

with this

 RichText child = RichText(
      text: TextSpan(children: [_buildTextSpan(context)]),
      textAlign: textAlign,
      textDirection: textDirection,
      strutStyle: strutStyle,
      textScaleFactor: MediaQuery.textScaleFactorOf(context),
    );

in TextLine builder. it worked for me.

image

@singerdmx
Copy link
Owner

singerdmx commented Feb 21, 2021

Nice
Pull request please?

@singerdmx
Copy link
Owner

singerdmx commented Feb 21, 2021

@ritheshSalyan let me know if u prefer us to submit the change instead or u want to send a pull request

@singerdmx
Copy link
Owner

The current code already return TextSpan(children: children, style: textStyle) per below. I wonder what your change did:

  TextSpan _buildTextSpan(BuildContext context) {
    DefaultStyles defaultStyles = styles;
    List<TextSpan> children = line.children
        .map((node) => _getTextSpanFromNode(defaultStyles, node))
        .toList(growable: false);

    TextStyle textStyle = TextStyle();

    if (line.style.containsKey(Attribute.placeholder.key)) {
      textStyle = defaultStyles.placeHolder.style;
      return TextSpan(children: children, style: textStyle);
    }

    Attribute header = line.style.attributes[Attribute.header.key];
    Map<Attribute, TextStyle> m = {
      Attribute.h1: defaultStyles.h1.style,
      Attribute.h2: defaultStyles.h2.style,
      Attribute.h3: defaultStyles.h3.style,
    };

    textStyle = textStyle.merge(m[header] ?? defaultStyles.paragraph.style);

    Attribute block = line.style.getBlockExceptHeader();
    TextStyle toMerge;
    if (block == Attribute.blockQuote) {
      toMerge = defaultStyles.quote.style;
    } else if (block == Attribute.codeBlock) {
      toMerge = defaultStyles.code.style;
    } else if (block != null) {
      toMerge = defaultStyles.lists.style;
    }

    textStyle = textStyle.merge(toMerge);

    return TextSpan(children: children, style: textStyle);
  }

@singerdmx
Copy link
Owner

Is this your change?
image

@ritheshSalyan
Copy link
Author

yes.

@singerdmx
Copy link
Owner

@ritheshSalyan I submitted d644223 packing this change
May I resolve this now?

@singerdmx
Copy link
Owner

image

@singerdmx
Copy link
Owner

@ritheshSalyan closing. If you still have issue you can reopen it

@ritheshSalyan
Copy link
Author

yes.

@ritheshSalyan
Copy link
Author

did you test it for bullet points and check attributes?

@singerdmx
Copy link
Owner

No, probably need to update sample_data.json for that

@ritheshSalyan
Copy link
Author

The bullet point is having issue.

image

image

@singerdmx singerdmx reopened this Feb 21, 2021
@singerdmx
Copy link
Owner

image

Corresponding code is here

@ArjanAswal
Copy link
Collaborator

Closing due to inactivity, feel free to reopen.

@NicolasDionB
Copy link
Contributor

I'm still having issues with this on the Web. I created custom toolbar where I have a list of different font sizes. I apply it with the SizeAttribute, for instance:

controller.formatSelection(SizeAttribute('24'));

Note that I'm using no custom style at all. Consider the following text and selection:
image
Applying the size 24, the result isn't as expected as the line height is miscalculated somehow. It's as the largest line height was used for the whole paragraph (look a the top of the paragraph). Everything is then misaligned.
image
Clicking at the end of the text you can see that even the cursor is misplaced:
image

Any idea how I could fix this?

@NicolasDionB
Copy link
Contributor

@ArjanAswal @singerdmx I think by re-reading this issue that the problem came back. Maybe it was fixed at some point but isn't anymore. Is it possible to re-open the issue?

@ArjanAswal ArjanAswal reopened this Feb 16, 2022
@NicolasDionB
Copy link
Contributor

@ArjanAswal @singerdmx Actually I found that the rendering mode "html" causes the problem. Using the default "canvaskit" mode fixes it. I also discussed a problem with empty line height here: #621.

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

4 participants