Beispiel #1
0
def text_dimensions(text, text_prop, dpi, at_angle=0):
    ren = vtkTextRenderer()
    bounds = [0, 0, 0, 0]
    p = vtkTextProperty()
    p.ShallowCopy(text_prop)
    p.SetOrientation(at_angle)
    ren.GetBoundingBox(p, text, bounds, dpi)
    return bounds[1] - bounds[0] + 1, bounds[3] - bounds[2] + 1
Beispiel #2
0
def text_dimensions(text, text_prop, dpi, at_angle=0):
    ren = vtkTextRenderer()
    bounds = [0, 0, 0, 0]
    p = vtkTextProperty()
    p.ShallowCopy(text_prop)
    p.SetOrientation(at_angle)
    ren.GetBoundingBox(p, text, bounds, dpi)
    return bounds[1] - bounds[0] + 1, bounds[3] - bounds[2] + 1
Beispiel #3
0
def text_box(text, text_prop, dpi, at_angle):
    ren = vtkTextRenderer()
    bounds = [0, 0, 0, 0]
    p = vtkTextProperty()
    p.ShallowCopy(text_prop)
    p.SetOrientation(at_angle)
    ren.GetBoundingBox(p, text, bounds, dpi)
    return bounds
Beispiel #4
0
def baseline_offsets(origin, new_string, text_prop):
    ren = vtkTextRenderer()

    bounds_origin = [0,0,0,0]
    ren.GetBoundingBox(text_prop, origin, bounds_origin)

    bounds_new = [0,0,0,0]
    ren.GetBoundingBox(text_prop, new_string, bounds_new)

    below_offset = bounds_origin[2] - bounds_new[2]

    above_offset = bounds_origin[3] - bounds_new[3]

    return below_offset, above_offset
Beispiel #5
0
def baseline_offsets(origin, new_string, text_prop):
    ren = vtkTextRenderer()

    bounds_origin = [0, 0, 0, 0]
    ren.GetBoundingBox(text_prop, origin, bounds_origin)

    bounds_new = [0, 0, 0, 0]
    ren.GetBoundingBox(text_prop, new_string, bounds_new)

    below_offset = bounds_origin[2] - bounds_new[2]

    above_offset = bounds_origin[3] - bounds_new[3]

    return below_offset, above_offset
Beispiel #6
0
    def text(
        self,
        txt,
        pos=(0, 0, 0),
        s=1,
        c=None,
        alpha=1,
        bg=None,
        font="Theemim",
        dpi=500,
        justify="bottom-left",
    ):
        """Build an image from a string."""

        if c is None:  # automatic black or white
            if settings.plotter_instance and settings.plotter_instance.renderer:
                c = (0.9, 0.9, 0.9)
                if np.sum(settings.plotter_instance.renderer.GetBackground()
                          ) > 1.5:
                    c = (0.1, 0.1, 0.1)
            else:
                c = (0.3, 0.3, 0.3)

        r = vtk.vtkTextRenderer()
        img = vtk.vtkImageData()

        tp = vtk.vtkTextProperty()
        tp.BoldOff()
        tp.SetColor(colors.getColor(c))
        tp.SetJustificationToLeft()
        if "top" in justify:
            tp.SetVerticalJustificationToTop()
        if "bottom" in justify:
            tp.SetVerticalJustificationToBottom()
        if "cent" in justify:
            tp.SetVerticalJustificationToCentered()
            tp.SetJustificationToCentered()
        if "left" in justify:
            tp.SetJustificationToLeft()
        if "right" in justify:
            tp.SetJustificationToRight()

        if font.lower() == "courier": tp.SetFontFamilyToCourier()
        elif font.lower() == "times": tp.SetFontFamilyToTimes()
        elif font.lower() == "arial": tp.SetFontFamilyToArial()
        else:
            tp.SetFontFamily(vtk.VTK_FONT_FILE)
            if font in settings.fonts:
                tp.SetFontFile(settings.fonts_path + font + '.ttf')
            elif os.path.exists(font):
                tp.SetFontFile(font)
            else:
                colors.printc("\sad Font",
                              font,
                              "not found in",
                              settings.fonts_path,
                              c="r")
                colors.printc("\pin Available fonts are:",
                              settings.fonts,
                              c="m")
                return None

        if bg:
            bgcol = colors.getColor(bg)
            tp.SetBackgroundColor(bgcol)
            tp.SetBackgroundOpacity(alpha * 0.5)
            tp.SetFrameColor(bgcol)
            tp.FrameOn()

        #GetConstrainedFontSize (const vtkUnicodeString &str,
        # vtkTextProperty *tprop, int targetWidth, int targetHeight, int dpi)
        fs = r.GetConstrainedFontSize(txt, tp, 900, 1000, dpi)
        tp.SetFontSize(fs)

        r.RenderString(tp, txt, img, [1, 1], dpi)
        # RenderString (vtkTextProperty *tprop, const vtkStdString &str,
        #   vtkImageData *data, int textDims[2], int dpi, int backend=Default)

        self.SetInputData(img)
        self.GetMapper().Modified()

        self.SetPosition(pos)
        x0, x1 = self.xbounds()
        if x1 != x0:
            sc = s / (x1 - x0)
            self.SetScale(sc, sc, sc)
        return self
Beispiel #7
0
def text_dimensions(text, text_prop):
    ren = vtkTextRenderer()
    bounds = [0,0,0,0]
    ren.GetBoundingBox(text_prop, text, bounds)
    return bounds[1] - bounds[0], bounds[3] - bounds[2]
Beispiel #8
0
def text_dimensions(text, text_prop):
    ren = vtkTextRenderer()
    bounds = [0, 0, 0, 0]
    ren.GetBoundingBox(text_prop, text, bounds)
    return bounds[1] - bounds[0], bounds[3] - bounds[2]