Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:31:52+00:00 2026-05-25T20:31:52+00:00

The application I’m writing uses libcairo to output vector graphics; everything works fine for

  • 0

The application I’m writing uses libcairo to output vector graphics; everything works fine for output formats that support multiple pages (PDF, PostScript), however I would like to also support SVG and raster image formats.

I’m currently simply pushing pages using showPage whenever I would otherwise overflow the bottom margin, and I would like keeping the code structured this way. I have come up with two theroretically possible solutions:

a) A helper monad that wraps around Cairo’s Render monad, but provides a flushPage action which, when chained into it, pushes the current Render action onto an internal page stack, a liftRender action that would, well, lift a Render action into the monad by chaining it onto the previously buffered action, and a helper function to extract a list of Render () actions, one for each page. So I would simply call my main rendering function, but instead of a Render () action, it would return a pagination-wrapper action, from which I would then extract individual pages and process them – for multi-page formats, I could simply chain them together, inserting showPage actions between them, while for single-page formats, I would render them individually. As an example, here’s what it would look like:

-- original code
renderMe :: Render ()
renderMe = do
    newPath
    moveTo 10 10
    lineTo 20 20
    lineTo 10 30
    lineTo 10 10
    fill

    showPage

    newPath
    moveTo 10 10
    lineTo 20 20
    lineTo 10 30
    lineTo 10 10
    fill

-- new code
renderPages :: PagedRender ()
renderPages = do
    liftRender (do
        newPath
        moveTo 10 10
        lineTo 20 20
        lineTo 10 30
        lineTo 10 10
        fill)

    flushPage

    liftRender (do
        newPath
        moveTo 10 10
        lineTo 20 20
        lineTo 10 30
        lineTo 10 10
        fill)

    flushPage

b) A cairo surface type that acts like a multi-page document on the outside, but produces a series of single-page documents on the outside. This would be ideal, since it wouldn’t require any changes to the rendering code at all, but I’m not sure if it is possible to do this without messing with cairo itself at the source level.

So, the actual question: Does any of the above solutions already exist? As in, has anyone written either a ‘pagination wrapper monad’ or a ‘multi-page SVG surface’? And, in case the answer is ‘no’; which one of these is preferable, and how would you go about implementing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:31:53+00:00Added an answer on May 25, 2026 at 8:31 pm

    In case anyone is interested, I figured it out thanks to some friendly help from the guys at #haskell.

    Instead of writing a custom wrapper monad, my render function returns Render [Render ()]. I render fragments recursively, passing some state along, and on each iteration, I check whether the current operation would overflow the current page. If it would, then the recursive call appends a new page and tries again; otherwise, it chains the current operation onto the top page. The result is a list of Render () actions, one for each page.

    The main function, then, takes these Render() actions out of the result of the render function. Then it checks the desired output format; if it’s a multi-page format like PostScript or PDF, it simply chains the actions together, inserting showPage actions between them. If it’s a single-page format, it creates a new render surface for each page, and renders one page action onto it. The first page doubles as the context for the initial render call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application is sending email by using MFMailComposeViewController , everything works just fine. However after
Application : HTA (therefore IE) This is an application that uses SendKeys to populate
My application is completely navigation based and my query is that navigation based application
Application uses Entity Framework 4.1 with database first approach. I have in database a
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
my application use 10 threads that to read a lot of html file.similar the
Application flow An input file consists of multiple logical documents. Extract one input logical
Application use NHibernate. I Have object A that contains set of objects B. I
My application has to detect that the device connected to the Wi-Fi network is
My application was running fine until i added the following code to add an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.