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

Explicitly specify width and height for svg #11771

Closed
wants to merge 4 commits into from

Conversation

CirnoT
Copy link
Contributor

@CirnoT CirnoT commented Jun 5, 2020

Lot of octicons are not ideally 16x16. The issues were mostly invisible but they could be noticed for fold icon having improper positioning. What made it very visible is recently introduced internal icon which looks awful with 16px width.

Refactored svg template helper to accept width and height explicitly and changed most visible octicons according to data from https://primer.style/octicons/

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 5, 2020

firefox_2020-06-05_15-20-18

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 5, 2020
@silverwind
Copy link
Member

I guess this is necessary for proper rendering of non-square SVGs but I wonder if there is maybe a more elegant solution to letterbox the icon within size pixels.

Do we know how many of the octicons are non-square? I imagine it would be only a small percentage.

@silverwind
Copy link
Member

Some non-square octicons can be observed in the logo of https://gist.github.com/. It does look like GitHub also just specifies both width and height there.

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 5, 2020

A good chunk of them are 14x16, just check commits. We also use variants where we increase size, so there most likely isn't any more elegant solution. GitHub also specifies them explicitly.

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 5, 2020

The new ones are explicitly 16x16 always https://primer.style/octicons-v2/ but are missing some icons we use and marked as not ready.

@silverwind
Copy link
Member

silverwind commented Jun 5, 2020

Their JSON file does have the dimensions in them:

$ cat node_modules/@primer/octicons/build/data.json | jq '.["internal-repo"].width,.["internal-repo"].height'
13
16

So I guess once we tackle #11618, we can just use their defined dimensions. I'd then make the width/height attributes optional in the template helper and default them to the defined size. Or update to v2 and assume 16px.

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 5, 2020

I'd then make the width/height attributes optional in the template helper and default them to the defined size. Or update to v2 and assume 16px.

Sounds good.

@silverwind
Copy link
Member

Still, I think it's rather inconvenient that one has to look up the icon size every time one needs to be added. Do you think it'd be much work to integrate the data from that json file and make the width/height arguments optional via vararg?

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 5, 2020

I'd say parsing JSON would be 3/4 of work required for #11618.

@techknowlogick techknowlogick added the topic/ui Change the appearance of the Gitea UI label Jun 7, 2020
@techknowlogick techknowlogick added this to the 1.13.0 milestone Jun 7, 2020
@silverwind
Copy link
Member

I'm not sure of this is really worth it. For the repo icons, it would introduce inconsistent widths for the icons which can break horizontal alignment. Here's one icon at 16px, another at 13px width.

image

The increased width adds 1.5px whitespace left and right which I think is the best possible rendering and I don't think it looks awful at all. I tested this in Firefox and Chrome, both behaving similarily, not sure exactly what causes the blurriness in your example above.

Even if I add excessive width like 32px, it seems to correctly letterbox the icon for me:

image

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 7, 2020

@silverwind This only happens when there's an icon with improper width along with icon with proper width. Both internal and normal repo icons have different width but your example only adjusted one internal icon.

If you care to examine PR in full you should find out that if all icons are adjusted to their proper width, there is no horizontal alignment issue.

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 7, 2020

They don't appear blurry to me when in zoom, but on 100% at 1080p they look blurry to me on Firefox.

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 7, 2020

I agree that it is rather annoying to specify width explicitly. The alternative is to work on JSON parsing and handle it automatically like it should've been.

Also personally along with JSON parsing I would get rid of optional width and height and only allow float zoom to be given as option.

@silverwind
Copy link
Member

silverwind commented Jun 8, 2020

Maybe you can show a jsfiddle with what you mean with the two icon alignment? A quick test shows that SVGs always letterbox correctly for me. For example, if I force a width of 24px on the first SVG on https://gist.github.com/:

image

The only way I found to break the scaling is by adding a preserveAspectRatio="none" attribute:

image

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 8, 2020

I don't understand what you mean. You raised issue that two icons were horizontally mis-aligned for you when you adjusted width on one of them and I corrected you that if you properly specify correct width for all of them, then they are horizontally aligned properly (even if they have different native width like lock and repo icon)

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 8, 2020

Example of what this PR fixes for me:
firefox_2020-06-08_09-55-09

firefox_2020-06-08_09-55-24

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 8, 2020

The specific case of this icon being blurry is because it's kind of special in whole octicon set - it's width is 13px. Setting it to 17px does not cause it to become blurry, but 16 or 18 does.

@lafriks
Copy link
Member

lafriks commented Jun 8, 2020

would it be possible to move these sizes out to some kind of map in golang code that would svg function automatically use so that you don't have to specify all in template files. If icon name is not in map it would render default 16x16

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 8, 2020

Thank you Firefox, I love you.

shape-rendering: crispEdges

via https://bugzilla.mozilla.org/show_bug.cgi?id=1003763#c1

The issue was apparently fixed but doesn't seem to be the case for me; possibly due to a font variation or rendering mechanism, who knows. Original bug at https://bugzilla.mozilla.org/show_bug.cgi?id=608812

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 8, 2020

@lafriks Yes it's to be done whenever we get to handle #11618

@CirnoT
Copy link
Contributor Author

CirnoT commented Jun 8, 2020

For what it's worth, it's blurry on Chromium on Windows for me too.

chrome_2020-06-08_10-14-43
chrome_2020-06-08_10-15-38

@silverwind
Copy link
Member

if you properly specify correct width for all of them, then they are horizontally aligned

How can they align with different width set on them? Is there another mechanism that corrects the width?

@CirnoT CirnoT closed this Jun 10, 2020
@CirnoT CirnoT deleted the wh-svg branch June 10, 2020 16:26
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/ui Change the appearance of the Gitea UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants