This file is indexed.

/usr/lib/python2.7/dist-packages/VisionEgg/Text.py is in python-visionegg 1.2.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# The Vision Egg: Text
#
# Copyright (C) 2001-2003 Andrew Straw.
# Copyright (C) 2005,2008 California Institute of Technology
#
# URL: <http://www.visionegg.org/>
#
# Distributed under the terms of the GNU Lesser General Public License
# (LGPL). See LICENSE.TXT that came with this file.

"""
Text stimuli.

"""

####################################################################
#
#        Import all the necessary packages
#
####################################################################

import logging
import logging.handlers

import VisionEgg.Core
import VisionEgg.Textures
import VisionEgg.ParameterTypes as ve_types

import VisionEgg.GL as gl # get all OpenGL stuff in one namespace

import pygame

try:
    import OpenGL.GLUT as glut
    have_glut = True
except:
    have_glut = False

_font_objects = {} # global variable to cache pygame font objects

def delete_font_objects():
    for key in _font_objects.keys():
        del _font_objects[key]

VisionEgg.Core.pygame_keeper.register_func_to_call_on_quit(delete_font_objects)

class Text(VisionEgg.Textures.TextureStimulus):
    """Single line of text rendered using pygame/SDL true type fonts.

    Parameters
    ==========
    anchor                -- specifies how position parameter is interpreted (String)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: lowerleft
    angle                 -- units: degrees, 0=right, 90=up (Real)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: 0.0
    color                 -- texture environment color. alpha ignored (if given) for max_alpha parameter (AnyOf(Sequence3 of Real or Sequence4 of Real))
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: (1.0, 1.0, 1.0)
    depth_test            -- perform depth test? (Boolean)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: False
    ignore_size_parameter -- (Boolean)
                             Default: True
    mask                  -- optional masking function (Instance of <class 'VisionEgg.Textures.Mask2D'>)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: (determined at runtime)
    max_alpha             -- controls opacity. 1.0=copletely opaque, 0.0=completely transparent (Real)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: 1.0
    on                    -- draw stimulus? (Boolean)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: True
    position              -- units: eye coordinates (AnyOf(Sequence2 of Real or Sequence3 of Real or Sequence4 of Real))
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: (0.0, 0.0)
    size                  -- defaults to texture data size (units: eye coordinates) (Sequence2 of Real)
                             Inherited from VisionEgg.Textures.TextureStimulus
                             Default: (determined at runtime)
    text                  -- (AnyOf(String or Unicode))
                             Default: the string to display
    texture               -- source of texture data (Instance of <class 'VisionEgg.Textures.Texture'>)
                             Inherited from VisionEgg.Textures.TextureStimulusBaseClass
                             Default: (determined at runtime)
    texture_mag_filter    -- OpenGL filter enum (Integer)
                             Inherited from VisionEgg.Textures.TextureStimulusBaseClass
                             Default: GL_LINEAR (9729)
    texture_min_filter    -- OpenGL filter enum (Integer)
                             Inherited from VisionEgg.Textures.TextureStimulusBaseClass
                             Default: (GL enum determined at runtime)
    texture_wrap_s        -- OpenGL texture wrap enum (Integer)
                             Inherited from VisionEgg.Textures.TextureStimulusBaseClass
                             Default: (GL enum determined at runtime)
    texture_wrap_t        -- OpenGL texture wrap enum (Integer)
                             Inherited from VisionEgg.Textures.TextureStimulusBaseClass
                             Default: (GL enum determined at runtime)

    Constant Parameters
    ===================
    font_name         -- (AnyOf(String or Unicode))
                         Default: (determined at runtime)
    font_size         -- (UnsignedInteger)
                         Default: 30
    internal_format   -- format with which OpenGL uses texture data (OpenGL data type enum) (Integer)
                         Inherited from VisionEgg.Textures.TextureStimulus
                         Default: GL_RGB (6407)
    mipmaps_enabled   -- Are mipmaps enabled? (Boolean)
                         Inherited from VisionEgg.Textures.TextureStimulus
                         Default: True
    shrink_texture_ok -- Allow automatic shrinking of texture if too big? (Boolean)
                         Inherited from VisionEgg.Textures.TextureStimulus
                         Default: False
    """

    parameters_and_defaults = {
        'text': ( 'the string to display', #changing this redraws texture, may cause slowdown
                  ve_types.AnyOf(ve_types.String,ve_types.Unicode)),
        'ignore_size_parameter':(True, # when true, draws text at 100% size
                                 ve_types.Boolean),
        }

    constant_parameters_and_defaults = {
        'font_size':(30,
                     ve_types.UnsignedInteger),
        'font_name':(None, # None = use default font
                     ve_types.AnyOf(ve_types.String,ve_types.Unicode)),
        }

    __slots__ = (
        'font',
        '_text',
        )

    def __init__(self,**kw):
        if not pygame.font:
            raise RuntimeError("no pygame font module")
        if not pygame.font.get_init():
            pygame.font.init()
            if not pygame.font.get_init():
                raise RuntimeError("pygame doesn't init")
        # override some defaults
        if 'internal_format' not in kw.keys():
            kw['internal_format'] = gl.GL_RGBA
        if 'mipmaps_enabled' not in kw.keys():
            kw['mipmaps_enabled'] = 0
        if 'texture_min_filter' not in kw.keys():
            kw['texture_min_filter'] = gl.GL_LINEAR
        VisionEgg.Textures.TextureStimulus.__init__(self,**kw)
        cp = self.constant_parameters
        fontobject_args = (cp.font_name,cp.font_size)
        if fontobject_args not in _font_objects:
            # make global cache of font objects
            fontobject = pygame.font.Font(*fontobject_args)
            _font_objects[fontobject_args] = fontobject
        # get font object from global cache
        self.font = _font_objects[fontobject_args]
        self._render_text()

    def _render_text(self):
        p = self.parameters
        rendered_surf = self.font.render(p.text, 1, (255,255,255)) # pygame.Surface object

        # we could use put_new_image for speed (or put_sub_image for more)
        p.texture = VisionEgg.Textures.Texture(rendered_surf)
        self._reload_texture()
        self._text = p.text # cache string so we know when to re-render
        if p.ignore_size_parameter:
            p.size = p.texture.size

    def draw(self):
        p = self.parameters
        if p.texture != self._using_texture: # self._using_texture is from TextureStimulusBaseClass
            raise RuntimeError("my texture has been modified, but it shouldn't be")
        if p.text != self._text: # new text
            self._render_text()
        if p.ignore_size_parameter:
            p.size = p.texture.size
        VisionEgg.Textures.TextureStimulus.draw(self) # call base class

if have_glut:

    class GlutTextBase(VisionEgg.Core.Stimulus):
        """DEPRECATED. Base class: don't instantiate this class directly.

        Base class that defines the common interface between the
        other glut-based text stimuli.

        Parameters
        ==========
        color     -- (AnyOf(Sequence3 of Real or Sequence4 of Real))
                     Default: (1.0, 1.0, 1.0)
        lowerleft -- (Sequence2 of Real)
                     Default: (320, 240)
        on        -- (Boolean)
                     Default: True
        text      -- (String)
                     Default: the string to display
        """

        parameters_and_defaults = {
            'on':(True,
                  ve_types.Boolean),
            'color':((1.0,1.0,1.0),
                     ve_types.AnyOf(ve_types.Sequence3(ve_types.Real),
                                    ve_types.Sequence4(ve_types.Real))),
            'lowerleft':((320,240),
                         ve_types.Sequence2(ve_types.Real)),
            'text':('the string to display',
                    ve_types.String)}

        def __init__(self,**kw):
            if not hasattr(VisionEgg.config,"_GAVE_GLUT_TEXT_DEPRECATION"):
                logger = logging.getLogger('VisionEgg.Text')
                logger.warning("Using GlutTextBase class.  This will be "
                               "removed in a future release. Use "
                               "VisionEgg.Text.Text instead.")
                VisionEgg.config._GAVE_GLUT_TEXT_DEPRECATION = 1
                VisionEgg.Core.Stimulus.__init__(self,**kw)

    class BitmapText(GlutTextBase):
        """DEPRECATED. Bitmap fonts from GLUT.

        Parameters
        ==========
        color     -- (AnyOf(Sequence3 of Real or Sequence4 of Real))
                     Inherited from GlutTextBase
                     Default: (1.0, 1.0, 1.0)
        font      -- (Integer)
                     Default: 5
        lowerleft -- (Sequence2 of Real)
                     Inherited from GlutTextBase
                     Default: (320, 240)
        on        -- (Boolean)
                     Inherited from GlutTextBase
                     Default: True
        text      -- (String)
                     Inherited from GlutTextBase
                     Default: the string to display
        """

        parameters_and_defaults = {
            'font':(glut.GLUT_BITMAP_TIMES_ROMAN_24,
                    ve_types.Integer),
            }

        def __init__(self,**kw):
            GlutTextBase.__init__(self,**kw)

        def draw(self):
            if self.parameters.on:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glDisable(gl.GL_BLEND)
                gl.glDisable(gl.GL_DEPTH_TEST)

                gl.glMatrixMode(gl.GL_MODELVIEW)
                gl.glPushMatrix()
                gl.glTranslate(self.parameters.lowerleft[0],self.parameters.lowerleft[1],0.0)

                c = self.parameters.color

                if len(c)==3:
                    gl.glColor3f(*c)
                elif len(c)==4:
                    gl.glColor4f(*c)
                gl.glDisable(gl.GL_TEXTURE_2D)

                gl.glRasterPos3f(0.0,0.0,0.0)
                for char in self.parameters.text:
                    glut.glutBitmapCharacter(self.parameters.font,ord(char))
                gl.glPopMatrix()

    class StrokeText(GlutTextBase):
        """DEPRECATED. Text rendered by GLUT using stroke fonts.

        Parameters
        ==========
        anti_aliasing -- (Boolean)
                         Default: True
        color         -- (AnyOf(Sequence3 of Real or Sequence4 of Real))
                         Inherited from GlutTextBase
                         Default: (1.0, 1.0, 1.0)
        font          -- (Integer)
                         Default: 0
        linewidth     -- (Real)
                         Default: 3.0
        lowerleft     -- (Sequence2 of Real)
                         Inherited from GlutTextBase
                         Default: (320, 240)
        on            -- (Boolean)
                         Inherited from GlutTextBase
                         Default: True
        orientation   -- (Real)
                         Default: 0.0
        text          -- (String)
                         Inherited from GlutTextBase
                         Default: the string to display
        """

        parameters_and_defaults = {
            'font':(glut.GLUT_STROKE_ROMAN,
                    ve_types.Integer),
            'orientation':(0.0,
                           ve_types.Real),
            'linewidth':(3.0, # pixels
                         ve_types.Real),
            'anti_aliasing':(True,
                             ve_types.Boolean),
            }

        def __init__(self,**kw):
            raise NotImplementedError("There's something broken with StrokeText, and I haven't figured it out yet!")
            GlutTextBase.__init__(self,**kw)

        def draw(self):
            if self.parameters.on:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glDisable(gl.GL_DEPTH_TEST)

                gl.glMatrixMode(gl.GL_MODELVIEW)
                gl.glPushMatrix()
                gl.glTranslate(self.parameters.lowerleft[0],self.parameters.lowerleft[1],0.0)
                gl.glRotate(self.parameters.orientation,0.0,0.0,1.0)

                c = self.parameters.color
                if len(c)==3:
                    gl.glColor3f(*c)
                elif len(c)==4:
                    gl.glColor4f(*c)

                gl.glLineWidth(self.parameters.linewidth)

                if self.parameters.anti_aliasing:
                    gl.glEnable(gl.GL_BLEND)
                    gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
                    gl.glEnable(gl.GL_LINE_SMOOTH)
                else:
                    gl.glDisable(gl.GL_BLEND)

    ##            # This code successfully draws a box...
    ##            gl.glBegin(gl.GL_QUADS)
    ##            gl.glVertex2f(0.0,0.0)
    ##            gl.glVertex2f(0.0,0.1)
    ##            gl.glVertex2f(0.1,0.1)
    ##            gl.glVertex2f(0.1,0.0)
    ##            gl.glEnd()

                # But this code does not draw the string!?!
                for char in self.parameters.text:
                    glut.glutStrokeCharacter(self.parameters.font,ord(char))
                gl.glPopMatrix()