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

Possible bug in Pro text API #201

Closed
cormullion opened this issue Oct 22, 2017 · 2 comments
Closed

Possible bug in Pro text API #201

cormullion opened this issue Oct 22, 2017 · 2 comments

Comments

@cormullion
Copy link
Member

In some Luxor testing I found a problem with the Pro text API, and here's the same problem reproduced in Cairo:

sample_pango_text

The blue area has been applied to the second "Hamburgefons" string, looks like it's inherited from the previous text with markup. I'm hoping this is a bug -- but of course I may have misunderstood how it's supposed to work.

## header to provide surface and context
using Cairo
c = CairoRGBSurface(256,256)
cr = CairoContext(c)

Cairo.save(cr)
set_source_rgb(cr,0.8,0.8,0.8)    # light gray
rectangle(cr,0.0,0.0,256.0,256.0) # background
Cairo.fill(cr)
restore(cr)

Cairo.save(cr)

set_font_face(cr, "Sans 16")

Cairo.text(cr,16.0,40.0,"Hamburgefons")
Cairo.text(cr,16.0,72.0,"sp⁰¹²³,min⁻²,αΑβΒφϕΦγΓ")
Cairo.text(cr,16.0,104.0,"Text<b>Bold</b><i>Italic</i><sup>super-2</sup>",markup=true)
Cairo.text(cr,40.0,224.0,"Es geht <span foreground=\"white\" background=\"blue\">aufwärts</span> !",markup=true,angle=30.0)

# But this doesn't have markup...:

Cairo.text(cr,16.0,223.0,"Hamburgefons again")

#using textwidth and height 

set_font_face(cr, "Sans 12")

a = "A"
aheight = textheight(cr,a)
awidth = textwidth(cr,a)
atext = @sprintf("%s wd=%2.2f,ht=%2.2f",a,awidth,aheight)
Cairo.text(cr,16.0,240.0,atext,markup=true)


## mark picture with current date
Cairo.restore(cr)
move_to(cr,0.0,12.0)
set_source_rgb(cr, 0,0,0)
show_text(cr,Libc.strftime(time()))
write_to_png(c,"/tmp/sample_pango_text.png")

You can also get other aspects of the markup leaking into other strings (eg bold, superscript).

julia> Pkg.status("Cairo")
 - Cairo                         0.3.1

julia> versioninfo()
Julia Version 0.6.0
Commit 903644385b (2017-06-19 13:05 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-2500S CPU @ 2.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, sandybridge)
@lobingera
Copy link
Contributor

lobingera commented Oct 23, 2017

I have recognized similar problems when writing the demo code. I'm not a pango expert, but i think the main problem is reusing the pango-context in multiple lines. You could try to create a new Cairo.context which creates a new pango context implicitly.

In the long-run, a new text API and doing a clean split of cairo and pango seems to be needed,

@lobingera
Copy link
Contributor

#226

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

2 participants