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

loop when rendering text #59

Closed
byorgey opened this issue Feb 8, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@byorgey
Copy link
Member

commented Feb 8, 2015

The cairo backend yields <<loop>> when I try to run the following program:

{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine

import Control.Arrow
import Data.List

import Diagrams.TwoD.Layout.Tree hiding (leaf)
import Data.Tree

cunit :: String -> Tree String
cunit x = Node (x ++ ".o") [ Node (x ++ ".c") [] ]

t :: Tree String
t = Node "prog.exe"
    [ cunit "foo"
    , cunit "bar"
    , cunit "baz"
    ]

dia :: Diagram B
dia = lw thin
    . frame 0.5
    . renderTree (\t -> text t # fc (pickColor t) # fontSizeL 0.8 <> roundedRect 6 2 0.5 # fc white) (~~)
    . (fmap . second) reflectY
    . symmLayout' (with & slWidth  .~ const (-3,3)
                        & slHeight .~ const (-1,1)
                        & slHSep   .~ 2
                        & slVSep   .~ 2
                  )
    $ t    -- $

pickColor t
  | "c" `isSuffixOf` t = blue
  | "o" `isSuffixOf` t = green
  | otherwise          = red

main = defaultMain dia

When I am not working frantically on a talk I will try to come up with a stripped-down version. This example renders fine with the SVG backend.

@byorgey byorgey added the bug label Feb 8, 2015

@byorgey byorgey changed the title loop when rendering tree loop when rendering text Feb 9, 2015

@byorgey

This comment has been minimized.

Copy link
Member Author

commented Feb 9, 2015

The culprit seems to be text. The following code causes <<loop>> to be printed:

import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine

main = defaultMain (text "abc" <> square 1)

It still gives <<loop>> even with the square 1 taken away as well.

@byorgey

This comment has been minimized.

Copy link
Member Author

commented Feb 9, 2015

Well, that was easy to find:

let tr = tr <> reflectionY

oops. See here: https://github.com/diagrams/diagrams-cairo/blob/master/src/Diagrams/Backend/Cairo/Internal.hs#L402

Simple fix coming shortly.

@byorgey byorgey closed this in 5b1723d Feb 9, 2015

@bergey

This comment has been minimized.

Copy link
Member

commented Feb 9, 2015

[sigh] We need regression tests. I need to look at how the new Measure works; I don't understand the Text instance post-64ec0c4

@cchalmers

This comment has been minimized.

Copy link
Member

commented Feb 9, 2015

Looks like this happened because of a mixup in merging. I didn't test it because I don't have Cairo installed so and #57 ended up getting merged without getting checked.

As for the changes for the new measure, basically the tt in Text only captures the non-scaling transform (so the (avgScale tt *) bit in my commit is actually redundant). All scaling is recorded in the FontSizeM attribute. Looking back I should have written a bit more explaining it.

I also had to include a Recommend in the font size because the default size is local. Otherwise if the user doesn't specify a font size, none of the scaling gets recorded. Another consequence is any local scaling before committing a font size is ignored. But this is consistent with how other measured attributes work.

@bergey

This comment has been minimized.

Copy link
Member

commented Feb 9, 2015

Your explanation is very helpful. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.