Wide 'W'

A forum for general AmigaOS 4.x support questions that are not platform-specific
djg
Posts: 30
Joined: Sat Jan 26, 2013 5:00 pm

Wide 'W'

Post by djg »

Hi,

I may have found a small bug. When I open a non proportional font like DejaVu Sans and write to a window right next to the left border using IGraphics->Text(rp, Window->BorderLeft, y), and the first character is a 'W', a column of one pixel wide is cleared from the left border.

Am I write or wrong?
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1483
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: Wide 'W'

Post by tonyw »

I seem to remember from years ago that some Locales (and fonts) do that. I can't offer you a fix.

If you could provide a code example, (and all your system settings), we can test it and write a report for you.
cheers
tony
djg
Posts: 30
Joined: Sat Jan 26, 2013 5:00 pm

Re: Wide 'W'

Post by djg »

tonyw wrote:I seem to remember from years ago that some Locales (and fonts) do that. I can't offer you a fix.

If you could provide a code example, (and all your system settings), we can test it and write a report for you.

I guess I will have to work around this then by writing at least one pixel to the right.
I don't know how to gather all my system settings, but I've tried it on a fresh install of Update 1 on a new partition, and it happened there too.
My computer is a SAM440ep, and the screenmode is Radeon M9:1024x768 ARGB for Update 1 or RADEON M9:1920x1080 RGB16 for Update 6,
although I don't think that matters.

It looks like this:
Font Test Window
Font Test Window
FontTest.png (4.58 KiB) Viewed 5493 times
Below is my code:

Code: Select all

;/* FontTest
gcc -o FontTest FontTest.c -Wall -Werror -lauto
quit
*/

#include <intuition/intuition.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/diskfont.h>

#include "stdio.h"	/*  for printf()  */
#include "stdlib.h"	/*  for exit()  */
#include "string.h"	/*  for strlen()  */

struct Window *Window = NULL;
struct TextFont *TextFont = NULL;

void CloseAll(void)
{
    if (TextFont) IGraphics->CloseFont(TextFont);
    if (Window) IIntuition->CloseWindow(Window);
}

void Fail(char *failString)
{
    printf("%s\n", failString);
    CloseAll();
    exit(FALSE);
}

void OpenAll(void)
{
    static char WindowTitle[] = "Font Test";
    struct TextAttr textAttr = { "DejaVu Sans.font", 16, 0, 0 };

    if (!(TextFont = IDiskfont->OpenDiskFont(&textAttr)))
        Fail("could not open font");

    if (!(Window = IIntuition->OpenWindowTags(NULL,
                       WA_Title, WindowTitle,
                       WA_Width, 200,
                       WA_Height, 100,
                       WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET,
                       WA_IDCMP, IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW | IDCMP_CLOSEWINDOW)))
        Fail("could not open window");
}

void FontTest(void)
{
    char testString[] = "Write Test";
    struct RastPort *rp = Window->RPort;

    IGraphics->SetFont(rp, TextFont);
    IGraphics->SetAPen(rp, 1);
    IGraphics->Move(rp, Window->BorderLeft, Window->BorderTop + rp->TxBaseline);
    IGraphics->Text(rp, testString, strlen(testString));
}

int main(void)
{
    BOOL done;
    struct IntuiMessage *imsg;

    OpenAll();
    FontTest();

    done = FALSE;
    while (!done)
    {
        imsg = (struct IntuiMessage *) IExec->GetMsg(Window->UserPort);
        if (!imsg)
        {
            IExec->Wait(1 << Window->UserPort->mp_SigBit);
            continue;
        }

        if (imsg)
        {
            switch (imsg->Class)
            {
                case IDCMP_CLOSEWINDOW:
                    done = TRUE;
                    break;

                case IDCMP_ACTIVEWINDOW:
                case IDCMP_INACTIVEWINDOW:
                    FontTest();
                    break;
            }
            IExec->ReplyMsg((struct Message *) imsg);
        }
    }

    CloseAll();

    return 0;
}
User avatar
thomasrapp
Posts: 318
Joined: Sun Jun 19, 2011 12:22 am

Re: Wide 'W'

Post by thomasrapp »

May be a problem with the font. The same happens on OS 3.9 with ttf.library and DejaVuSans.ttf from dejavu-fonts.org.
User avatar
gazelle
Posts: 102
Joined: Sun Mar 04, 2012 12:49 pm
Location: Frohnleiten, Austria

Re: Wide 'W'

Post by gazelle »

Maybe because of a negative kerning of the "W".

You could check with the TextExtent:

Code: Select all

void FontTest(void)
{
    char testString[] = "Write Test";
    struct RastPort *rp = Window->RPort;
    struct TextExtent te;
    WORD x, y;

    IGraphics->SetFont(rp, TextFont);
    IGraphics->SetAPen(rp, 1);

    x = Window->BorderLeft;
    y = Window->BorderTop + rp->TxBaseline;
    
    IGraphics->TextExtent(rp, testString, strlen(testString), &te);
/*
    IDOS->Printf("MinX: %ld\n", te.te_Extent.MinX);
    IDOS->Printf("MinY: %ld\n", te.te_Extent.MinY);
    IDOS->Printf("MaxX: %ld\n", te.te_Extent.MaxX);
    IDOS->Printf("MaxY: %ld\n", te.te_Extent.MaxY);
*/
    if (te.te_Extent.MinX < 0)
    {
    	x = x - te.te_Extent.MinX;
    }

    IGraphics->Move(rp, x, y);
    IGraphics->Text(rp, testString, strlen(testString));
}
chris
Posts: 564
Joined: Sat Jun 18, 2011 12:05 pm
Contact:

Re: Wide 'W'

Post by chris »

gazelle wrote:Maybe because of a negative kerning of the "W".
If you're kerning, you need a character in front of the W to pair it with. There is no such character in the example, so no kerning of the left of the W should occur.
djg
Posts: 30
Joined: Sat Jan 26, 2013 5:00 pm

Re: Wide 'W'

Post by djg »

chris wrote:
gazelle wrote:Maybe because of a negative kerning of the "W".
If you're kerning, you need a character in front of the W to pair it with. There is no such character in the example, so no kerning of the left of the W should occur.
Since gazelle's suggestion works (here), it seems to me that kerning of the 'W' with its non-existing predecessor does occur when it should not. But that's just a thought, before this I had never heard of kerning.
User avatar
gazelle
Posts: 102
Joined: Sun Mar 04, 2012 12:49 pm
Location: Frohnleiten, Austria

Re: Wide 'W'

Post by gazelle »

I wasn't happy about the use of the term "kerning" but used it for lack of knowing a better one.

It seems to be a bug in the font, because with Verdana or Arial it doesn't happen.

edit:
Ok, after some more tests I found out that with size 15 or 17 (DejaVu Sans) it doesn't happen. So the bug is more likely in the fontengine not the font.
djg
Posts: 30
Joined: Sat Jan 26, 2013 5:00 pm

Re: Wide 'W'

Post by djg »

gazelle wrote:I wasn't happy about the use of the term "kerning" but used it for lack of knowing a better one.

It seems to be a bug in the font, because with Verdana or Arial it doesn't happen.

edit:
Ok, after some more tests I found out that with size 15 or 17 (DejaVu Sans) it doesn't happen. So the bug is more likely in the fontengine not the font.
Ok, thanks. So it looks like it is a bug, even if it is a small one. Seems relatively easy to fix. Although I must say, I know very little about it.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK
Contact:

Re: Wide 'W'

Post by broadblues »

I can't see that there is any bug here, you *should* check your textextent before rendering text and make any adjustments required for negative values etc.
Post Reply