Ticket #1298 (new enhancement)

Opened 3 months ago

include librsvg sub-element functions in svgcairo

Reported by: guest Owned by: somebody
Priority: normal Milestone: 0.13.0
Component: general (Gtk+, Glib) Version: 0.12.4
Keywords: svgcairo, subelement, rendering Cc: schugschug@…

Description

Can the following sub functions be added to cairo rsvg_handle_render_cairo_sub, rsvg_handle_get_position_sub, rsvg_handle_get_size_sub, rsvg_handle_has_sub

-- | render subelement an SVG file by ID
--
-- Returns @False@ if an error was detected.
-- On librsvg before 2.22.3, @svgRender@ always returns @True@.
svgRenderSub :: SVG -> String -> Render Bool
svgRenderSub svg sub = do
  cr <- ask
  ret <- liftIO $ withCString sub $ \csub -> {# call unsafe render_cairo_sub #} svg cr csub
#if ! LIBRSVG_CHECK_VERSION(2,22,3)
  return True
#else
  return (ret /= 0)
#endif

-- | Get the width and height of the SVG subelement by ID.
--
svgGetSizeSub :: 
    SVG
 -> String
 -> (Int, Int) -- ^ @(width, height)@
svgGetSizeSub svg sub = Unsafe.unsafePerformIO $
#if ! LIBRSVG_CHECK_VERSION(2,22,0)
  return (0,0)
#else
  allocaBytes {# sizeof RsvgDimensionData #} $ \dimentionsPtr -> do
  withCString sub $ \csub -> {# call unsafe get_dimensions_sub #} svg dimentionsPtr csub
  width  <- {# get RsvgDimensionData->width  #} dimentionsPtr
  height <- {# get RsvgDimensionData->height #} dimentionsPtr
  return (fromIntegral width, fromIntegral height)
#endif

-- | Get the position of the SVG subelement by ID.
--
svgGetPositionSub :: 
    SVG
 -> String
 -> (Int, Int) -- ^ @(width, height)@
svgGetPositionSub svg sub = Unsafe.unsafePerformIO $
#if ! LIBRSVG_CHECK_VERSION(2,22,0)
  return (0,0)
#else
  allocaBytes {# sizeof RsvgPositionData #} $ \dimentionsPtr -> do
  withCString sub $ \csub -> {# call unsafe get_position_sub #} svg dimentionsPtr csub
  x <- {# get RsvgPositionData->x #} dimentionsPtr
  y <- {# get RsvgPositionData->y #} dimentionsPtr
  return (fromIntegral x, fromIntegral y)
#endif

-- | does subelement with ID exist in SVG
--
svgHasSub :: SVG -> String -> Render Bool
svgHasSub svg sub = do
#if ! LIBRSVG_CHECK_VERSION(2,22,0)
  return False
#else
  ret <- liftIO $ withCString sub $ \csub -> {# call unsafe has_sub #} svg csub
  return (ret /= 0)
#endif


Note: See TracTickets for help on using tickets.