I have annotations layer with that was imported from ArcGIS and want to set font in MapInfo.

ArcGIS annotations contains its settings inside annotations objects (in Shape field, as I guess) but this information duplicates in usual, non-gis string and integer fields (FontName, FontSize, Bold etc). I'm read font options from that fields and try to set text font:

Dim fs As Integer
Dim altering_obj As Object
' ...
Fetch Next From annotations
fs = annotations.bold + 2 * annotations.italic + 4 * annotations.underline
altering_obj = annotations.obj
Alter Object altering_obj
    Info OBJ_INFO_TEXTFONT, MakeFont(annotations.fontname, fs, annotations.fontsize, BLACK, -1)

Font name, style (bold, italic etc), color are applies but font size doesn't. May be I'm do wrong something? How can I change font size?

MapInfo versions is 10.5.2, and also I tried in very old 6.5.
Both versions has same behavior.


Text objects are not that easy to work with via MapBasic.

Back in 2003 Jacques Paris wrote a very comprehensive document on how to work with Text object via MapBasic: Handling MapInfo TEXT OBJECTS.

Have a read thru this document as it gives you good advice on how to work with text objects thru MapBasic.

Generally speaking you can't "just" change the point size of the text objects as the point size is related to the zoom of a map window. To quote Jackues:

Unlike other objects, the style of Text Objects cannot be modified programmatically to its fullest extent. This is due in particular to the way the height of such object is stored in the .map file. It is expressed in actual coordinate units by the YMIN YMAX coordinates of the rectangular box that will "enclose" the text. It is not thus possible to alter directly the size of a text by changing its point size, one must play with actual coordinates or find some devious ways to retrieve actual point size.

|improve this answer|||||

It doesn't look like you ever update the table with your new text object. Ideally, you would write a function to return the altered object which you could then use in an update statement.

e.g. (untested)

Sub Main

Dim fName as String,
    fStyle, fSize, fColor, bColor as Integer

    fName = "Arial"
    fStyle = 1
    fSize = 12
    fColor = BLACK
    bColor = -1

    Update myTableOfTextObjects set obj = AlterTextStyle(obj, fName, fStyle, fSize, fColor, bColor)

End Sub

Function AlterTextStyle(myObj as Object, fontName as String, fontStyle as Integer, 
                        fontSize as Integer, foreColor as Integer, backColor as Integer) as Object

    If ObjectInfo(myObj, OBJ_INFO_TYPE) = OBJ_TYPE_TEXT then
        Alter Object myObj
            Info OBJ_INFO_TEXTFONT, MakeFont(fontName, fontStyle, fontSize, foreColor, backColor)
    End if

    AlterTextStyle = myObj

End Function 
|improve this answer|||||
  • Thank you for advice, I already saves altered object in futher code by Update statement. Problem is in font size only, other properties sets and saves successfully. – General Failure Mar 2 '16 at 10:43
  • You may want to have a read of this: groups.google.com/forum/#!searchin/mapinfo-l/… I believe it has to do with the fact that a text object scales with the zoom of a map window so MapInfo handles (or doesn't!) the font 'size' a bit differently. I think in a map window the font size becomes dictated by the text bounding box (ie. height and width of the text box). I'm not sure there's an easy way to programatically adjust the text size when it's displayed in a map window but that thread may give you some ideas. – T_Bacon Mar 2 '16 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.