@ -20,30 +20,32 @@ cursorList = {
" cursor_up " : [ " circleOuter " ] ,
" cursor_up " : [ " circleOuter " ] ,
" cursor_poised " : [ " circleOuter " , " circleInnerOpen " ] ,
" cursor_poised " : [ " circleOuter " , " circleInnerOpen " ] ,
" cursor_clicked " : [ " circleOuter " , " circleInnerClosed " ] ,
" cursor_clicked " : [ " circleOuter " , " circleInnerClosed " ] ,
" cursor_disabled " : [ " circleOuter " , " c ross " ] ,
" cursor_disabled " : [ " cross " ] ,
" cursor_open " : [ " circleOuter " , " arrowGrey Upper " , " arrowGrey Lower " ] ,
" cursor_open " : [ " circleOuter " , " arrowTranslucent Upper " , " arrowTranslucent Lower " ] ,
" cursor_grab " : [ " circleOuter " , " circleInnerClosed " , " arrowGrey Upper " , " arrowGrey Lower " ] ,
" cursor_grab " : [ " circleOuter " , " circleInnerOpen " , " arrowTranslucent Upper " , " arrowTranslucent Lower " ] ,
" cursor_updown_open " : [ " circleOuter " , " circleInnerClosed " , " arrowGrey Upper " , " arrowGrey Lower " ] ,
" cursor_updown_open " : [ " circleOuter " , " circleInnerOpen " , " arrowTranslucent Upper " , " arrowTranslucent Lower " ] ,
" cursor_updown_closed " : [ " circleOuter " , " circleInnerClosed " , " arrowWhit eUpper " , " arrowWhit eLower " ] ,
" cursor_updown_closed " : [ " circleOuter " , " circleInnerClosed " , " arrowOpaqu eUpper " , " arrowOpaqu eLower " ] ,
" cursor_leftright_open " : [ " circleOuter " , " circleInnerClosed " , " arrowGreyRigh t " , " arrowGreyLef t " ] ,
" cursor_leftright_open " : [ " circleOuter " , " circleInnerOpen " , " arrowTranslucentLef t " , " arrowTranslucentRigh t " ] ,
" cursor_leftright_closed " : [ " circleOuter " , " circleInnerClosed " , " arrowWhiteRigh t " , " arrowWhiteLef t " ] ,
" cursor_leftright_closed " : [ " circleOuter " , " circleInnerClosed " , " arrowOpaqueLef t " , " arrowOpaqueRigh t " ] ,
" cursor_4way_open " : [ " circleOuter " , " circleInnerClosed " , " arrowGrey Upper " , " arrowGrey Right " , " arrowGrey Lower " , " arrowGrey Left " ] ,
" cursor_4way_open " : [ " circleOuter " , " circleInnerOpen " , " arrowTranslucent Upper " , " arrowTranslucent Right " , " arrowTranslucent Lower " , " arrowTranslucent Left " ] ,
" cursor_4way_closed " : [ " circleOuter " , " circleInnerClosed " , " arrowWhit eUpper " , " arrowWhit eRight " , " arrowWhit eLower " , " arrowWhit eLeft " ] ,
" cursor_4way_closed " : [ " circleOuter " , " circleInnerClosed " , " arrowOpaqu eUpper " , " arrowOpaqu eRight " , " arrowOpaqu eLower " , " arrowOpaqu eLeft " ] ,
" cursor_upward " : [ " circleOuter " , " arrowWhit eUpper " ] ,
" cursor_upward " : [ " circleOuter " , " arrowOpaqu eUpper " ] ,
" cursor_right " : [ " circleOuter " , " arrowWhit eRight " ] ,
" cursor_right " : [ " circleOuter " , " arrowOpaqu eRight " ] ,
" cursor_down " : [ " circleOuter " , " arrowWhit eLower " ] ,
" cursor_down " : [ " circleOuter " , " arrowOpaqu eLower " ] ,
" cursor_left " : [ " circleOuter " , " arrowWhit eLeft " ] ,
" cursor_left " : [ " circleOuter " , " arrowOpaqu eLeft " ] ,
" cursor_book " : [ " circleOuter " , " book " ] ,
" cursor_book " : [ " circleOuter " , " book " ] ,
" cursor_book_poised " : [ " circleOuter " , " circleInnerOpen " , " book " ] ,
" cursor_book_poised " : [ " circleOuter " , " circleInnerOpen " , " book " ] ,
" cursor_book_clicked " : [ " circleOuter " , " circleInnerClosed " , " book " ] ,
" cursor_book_clicked " : [ " circleOuter " , " circleInnerClosed " , " book " ] ,
}
}
cursorOffsetList = {
cursorOffsetList = {
" book " : [ 8 , 8 ]
" cursor_book " : [ 7 , 7 ] ,
" cursor_book_poised " : [ 7 , 7 ] ,
" cursor_book_clicked " : [ 7 , 7 ]
}
}
textList = {
textList = {
@ -62,6 +64,15 @@ def enable_only_layers(layerlist, layers):
layers [ layer ] . setAttribute ( " style " , " " )
layers [ layer ] . setAttribute ( " style " , " " )
else :
else :
layers [ layer ] . setAttribute ( " style " , " display:none " )
layers [ layer ] . setAttribute ( " style " , " display:none " )
# sanity check
for layer in layerlist :
if layer not in layers :
print ( " warning: unknown layer " , layer )
def shift_all_layers ( layers , shiftx , shifty ) :
# note: this assumes that all layers start out with no transform of their own
for layer in layers :
layers [ layer ] . setAttribute ( " transform " , " translate( %g , %g ) " % ( shiftx , shifty ) )
def get_layers_from_svg ( svgData ) :
def get_layers_from_svg ( svgData ) :
inkscapeNS = " http://www.inkscape.org/namespaces/inkscape "
inkscapeNS = " http://www.inkscape.org/namespaces/inkscape "
@ -75,13 +86,13 @@ def get_layers_from_svg(svgData):
return layers
return layers
def render_cursors ( inpath , outpath ) :
def render_cursors ( inpath , outpath ) :
resSize = { " width " : 32 , " height " : 32 }
scalefactor = 1
with open ( os . path . join ( inpath , " Cursor_Base.svg " ) , " r " ) as svgFile :
with open ( os . path . join ( inpath , " Cursor_Base.svg " ) , " r " ) as svgFile :
cursorSVG = parse ( svgFile )
cursorSVG = parse ( svgFile )
layers = get_layers_from_svg ( cursorSVG )
layers = get_layers_from_svg ( cursorSVG )
ratioW = resSize [ " width " ] / float ( cursorSVG . documentElement . getAttribute ( " width " ) )
svgwidth = float ( cursorSVG . documentElement . getAttribute ( " width " ) )
ratioH = resSize [ " height " ] / float ( cursorSVG . documentElement . getAttribute ( " height " ) )
svgheight = float ( cursorSVG . documentElement . getAttribute ( " height " ) )
surface = cairo . ImageSurface ( cairo . FORMAT_ARGB32 , resSize [ " width " ] , resSize [ " height " ] )
surface = cairo . ImageSurface ( cairo . FORMAT_ARGB32 , int ( math . ceil ( scalefactor * svgwidth ) ) , int ( math . ceil ( scalefactor * svgheight ) ) )
for cursor in cursorList :
for cursor in cursorList :
ctx = cairo . Context ( surface )
ctx = cairo . Context ( surface )
@ -90,13 +101,14 @@ def render_cursors(inpath, outpath):
ctx . paint ( )
ctx . paint ( )
ctx . restore ( )
ctx . restore ( )
enable_only_layers ( cursorList [ cursor ] , layers )
enabledlayers = cursorList [ cursor ]
enabledlayers = enabledlayers + [ l + " Shadow " for l in enabledlayers ]
enable_only_layers ( enabledlayers , layers )
shift_all_layers ( layers , * cursorOffsetList . get ( cursor , [ 0 , 0 ] ) )
for layerName in cursorOffsetList :
if layerName in cursorList [ cursor ] :
ctx . translate ( * cursorOffsetList [ layerName ] )
svg = rsvg . Handle ( data = cursorSVG . toxml ( ) )
svg = rsvg . Handle ( data = cursorSVG . toxml ( ) )
ctx . scale ( ratioW , ratioH )
ctx . scale ( scalefactor , scalefactor )
svg . render_cairo ( ctx )
svg . render_cairo ( ctx )
surface . write_to_png ( os . path . join ( outpath , cursor + " .png " ) )
surface . write_to_png ( os . path . join ( outpath , cursor + " .png " ) )