# fxRuby- text on canvas and fonts generating errors

**URL:** <https://www.ruby-forum.com/t/fxruby-text-on-canvas-and-fonts-generating-errors/48862>\
**Category:** Ruby\
**Created:** [November 25, 2005, 9:46pm UTC](https://www.ruby-forum.com/t/fxruby-text-on-canvas-and-fonts-generating-errors/48862 "2005-11-25T21:46:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![boxofsoxx-goognews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@boxofsoxx-goognews](https://www.ruby-forum.com/u/boxofsoxx-goognews)\
**Post date:** [November 25, 2005, 9:46pm UTC](https://www.ruby-forum.com/t/fxruby-text-on-canvas-and-fonts-generating-errors/48862/1 "2005-11-25T21:46:06Z")

</div>

I have a ruby program that uses FXRuby. I have created a canvas widget,  
and I can draw lines, rectangles and elipses, but if I try to draw  
text, I get the bizzare error shown below. I also get this error if I  
try to assign a FXfont to the canvas. I think I might be using the font  
incorrectly. Please help. Thanks.

The error is:  
This application has requested the Runtime to terminate it in an  
unusual way.  
Please contact the application’s support team for more information.

> Exit code: 3

This is the sample code that is a greatly reduced version of my code  
that still exhibits the problem. If Either line 58 or 59 is uncommented  
the error occurs.

#/usr/bin/env ruby  
require ‘fox14’  
require ‘fox14/colors’  
include Fox

class PlotterWindow \< FXMainWindow  
def initialize(app)  
# Invoke base class initialize first  
super(app, “Plotter”, nil, nil, DECOR\_ALL, 0, 0, 500, 700)  
@color4 = FXColor::LightBlue1  
@color5 = FXColor::Blue  
@font = FXFont.new(app,“times”,14)  
dumpFontDesc(“Initial Font”,@font.getFontDesc)  
#@font.setFont(“courier, 140”)

```
# Dialogs for later use
colorDialog = FXColorDialog.new(self, "Color Dialog")
# Create a font dialog for later use
@fontDialog = FXFontDialog.new(self, "Axis Font Dialog")
# Create a tooltip so we get tool tips for things in this window
FXToolTip.new(self.getApp())
statusbar = FXStatusBar.new(self,
  LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)

#BUTTONS
@rightFrame = FXVerticalFrame.new(self,

```

LAYOUT\_SIDE\_TOP|LAYOUT\_SIDE\_RIGHT|LAYOUT\_FILL\_Y)  
FXVerticalSeparator.new(self,  
LAYOUT\_SIDE\_RIGHT|LAYOUT\_FILL\_Y|SEPARATOR\_GROOVE)  
colorButton = FXButton.new(@rightFrame,  
“&Colors\tOpen Color Dialog\tOpen a dialog for selecting colors”,  
nil, colorDialog, FXWindow::ID\_SHOW,  
FRAME\_RAISED|FRAME\_THICK|LAYOUT\_FIX\_WIDTH|LAYOUT\_FIX\_HEIGHT, 0,  
0, 70, 30)  
fontButton = FXButton.new(@rightFrame,  
“&Axes\nFont\tChoose Axis Font\tSelect a font for the Axis  
Display”,  
nil, @fontDialog, FXWindow::ID\_SHOW,  
FRAME\_RAISED|FRAME\_THICK|LAYOUT\_FIX\_WIDTH|LAYOUT\_FIX\_HEIGHT,0, 0,  
70, 30)  
quitButton = FXButton.new(@rightFrame,  
“&Quit\tExit the Program\tTerminate Ruby Plot Program”,  
nil, nil, 0,  
FRAME\_RAISED|FRAME\_THICK|LAYOUT\_FIX\_WIDTH|LAYOUT\_FIX\_HEIGHT,0, 0,  
70, 30)  
quitButton.connect(SEL\_COMMAND) {  
getApp().exit(0)  
}

```
#CANVAS FRAME
canvasFrame = FXVerticalFrame.new(self,
  FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT,
  0, 0, 0, 0, 0,0,0,0)
@canvas = FXCanvas.new(canvasFrame, nil, 0,
  FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT)
@canvas.connect(SEL_PAINT) do |sender, sel, event|
  FXDCWindow.new(@canvas, event) do |dc|
    @canvas.backColor = @color4
    dc.foreground = @canvas.backColor
    dc.fillRectangle(event.rect.x, event.rect.y, event.rect.w,

```

event.rect.h)  
dc.foreground = @color5  
dc.drawEllipse(100,100,100,200)  
#dc.setFont(@font) #this generates an error  
#dc.drawText(100,100,“test”) #this generates an error  
end  
end  
end

def dumpFontDesc(lab,fd)  
print “fontDesc #{lab} = #{fd.inspect}\n”  
print “#{fd.face}, #{fd.size},#{fd.weight},”  
print “#{fd.slant}, #{fd.setwidth},#{fd.encoding},”  
print “#{fd.flags}\n\n”  
STDOUT.flush  
end

def create  
super  
show(PLACEMENT\_SCREEN)  
end  
end

if **FILE** == $0

# Construct an application

application = FXApp.new(“Button”, “FoxTest”)

# Construct the main window

PlotterWindow.new(application)

# Create the application

application.create

# Run it

application.run  
end
