WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Support SVG’s stroke-dasharray

Open cat6311 opened this issue 7 months ago • 4 comments

在使用svg 的 stroke-dasharray="10,10" 屬性後,html轉成pdf後 ,沒有生成對應的虛線。 <svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none">

cat6311 avatar May 26 '25 08:05 cat6311

Hi @cat6311,

Could you please write the issue in english?

grewn0uille avatar May 26 '25 09:05 grewn0uille

Hi @cat6311,

Could you please write the issue in english?

sorry. When using the stroke-dasharray="10,10" attribute of svg, the corresponding dashed lines are not generated as expected after converting HTML to PDF.

cat6311 avatar May 26 '25 09:05 cat6311

Yes, only the none value is supported. Related to #1346.

liZe avatar Jun 13 '25 19:06 liZe

Other values could probably be added, even by Python devs who don’t know WeasyPrint’s internal code. If anyone is interested, just ask, I can help!

liZe avatar Jun 17 '25 13:06 liZe

Hi @liZe ! I'd be very interested in contributing.

I'm comfortable with Python but, as you mentioned, I don't know the internals of WeasyPrint.

Could you provide some guidance on where I should start looking in the code to add this? I'm happy to do the research and work on a pull request.

FazleRabbbiferdaus172 avatar Aug 10 '25 17:08 FazleRabbbiferdaus172

Hi @FazleRabbbiferdaus172

Could you provide some guidance on where I should start looking in the code to add this? I'm happy to do the research and work on a pull request.

Hmmm… It’s embarrassing, but I think that everything actually works well already. Here’s an example from MDN:

<svg viewBox="0 0 30 12" xmlns="http://www.w3.org/2000/svg">
  <style>
    line {
      stroke: black;
    }
  </style>
  <!-- No dashes nor gaps -->
  <line x1="0" y1="1" x2="30" y2="1" />

  <!-- Dashes and gaps of the same size -->
  <line x1="0" y1="3" x2="30" y2="3" stroke-dasharray="4" />

  <!-- Dashes and gaps of different sizes -->
  <line x1="0" y1="5" x2="30" y2="5" stroke-dasharray="4 1" />

  <!-- Dashes and gaps of various sizes with an odd number of values -->
  <line x1="0" y1="7" x2="30" y2="7" stroke-dasharray="4 1 2" />

  <!-- Dashes and gaps of various sizes with an even number of values -->
  <line x1="0" y1="9" x2="30" y2="9" stroke-dasharray="4 1 2 3" />

  <!-- Dashes starting with a gap -->
  <line x1="0" y1="11" x2="30" y2="11" stroke-dasharray="0 4 0" />
</svg>
Image

Do you have an example that doesn’t work? If you don’t, then we can probably close this issue right now!

And if you just wanted to solve a good first issue in WeasyPrint, we can find a better one in the list. 😄

liZe avatar Aug 11 '25 10:08 liZe

I was just scrolling through the issues as I wanted to use it in a project. Would love to contribute and would appreciate it if you could point me to a good first issue. Thanks!

FazleRabbbiferdaus172 avatar Aug 12 '25 08:08 FazleRabbbiferdaus172

@FazleRabbbiferdaus172 #1961 is a good idea, with detailed steps. Don’t hesitate to ask if there’s anything that’s not clear, we’ll be happy to help!

liZe avatar Aug 12 '25 09:08 liZe