Closed Neon22 closed 1 month ago
Hmm, weird. Do the markup characters get generated in the RTF output? It looks like they should.
If they're there but the color isn't rendering properly, something might be off about the syntax and it would be worth looking at a minimal example of an RTF with colored text inside a table
Alas no - the call to cell.rtf_code returns a single text string of the text for the cell. These two generate exactly the same output:
rtf = Rtf()
rtf.add(Line("here is a table:"))
rtf.add(Table(
Row(Line("hello"), Line("world")),
Row(Line("hallo"), Line("Welt")),
))
rtf = Rtf()
rtf.add(Line("here is a table:"))
rtf.add(Table(
Row(Line("hello", color=Color(255, 0, 0)), Line("world", color=Color(0, 255, 0))),
Row(Line("hallo"), Line("Welt")),
))
The output is:
{\rtf1\ansi\deff0
here is a table:
\
\trowd
\cellx1000\cellx2000
\pard\intbl{hello}\cell
\pard\intbl{world}\cell
\row
\trowd
\cellx1000\cellx2000
\pard\intbl{hallo}\cell
\pard\intbl{Welt}\cell
\row
}
Note that the colors are not gathered either.
It appears that the Line() is not being processed as an RtfElement
if its inside a Table()
.
The issue is that Line
renders color based on the __cid__
field rather than the color
field, which doesn't get set within a table
Note that my aim is here is purely to get BGcolors on alternating table lines for clarity - and not to lose my mind implementing all the things :) Now that I have borders and padding in table - almost there.
Hmmm. reading up - it looks like the background color (say of a table cell) is given by a tag formatted like \clcbpat8
where the number is the index into the color table.
maybe the same color gathering you do as a preprocess could also gather any colors mentioned in the table. Is this possible ? Or is it better to add a color in a sep op and get the cid back then use that to mark a cell similar to what I am trying with the borders etc. ??
I got my color table info from:
{\f1\cb1\cf2 This is colored text. The background is color1 and the foreground is color 2.}
I am using Libreoffice to do my testing and doing compares between rtf files with diff flags.
Yeah I'm not sure its going to be easy to color text in tables. In Libreoffice it looks like they do it with style sheets so that's a bridge too far I think. Maybe a workaround for cell background color ? What's your opinion ?
I think a workaround for cell background color would be a good compromise for now. That's probably more common anyway compared to adding colored text within a table
add a PR to enable color of row of cells. That's probably it. Thanks heaps
Closed based on #11
BTW color in a cell does not come across and appear in the output. E.g.
Hmmm... Looks like it should work. Asks the Line for its rtf_code but it hasn't been rtf'd yet and so returns a plain string ??