Page 1 of 2

Wide 'W'

Posted: Thu Jan 16, 2014 10:03 pm
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?

Re: Wide 'W'

Posted: Thu Jan 16, 2014 11:23 pm
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.

Re: Wide 'W'

Posted: Fri Jan 17, 2014 3:32 pm
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 5491 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;
}

Re: Wide 'W'

Posted: Fri Jan 17, 2014 5:01 pm
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.

Re: Wide 'W'

Posted: Fri Jan 17, 2014 8:41 pm
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));
}

Re: Wide 'W'

Posted: Sat Jan 18, 2014 12:20 pm
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.

Re: Wide 'W'

Posted: Sat Jan 18, 2014 5:45 pm
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.

Re: Wide 'W'

Posted: Sat Jan 18, 2014 7:52 pm
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.

Re: Wide 'W'

Posted: Sun Jan 19, 2014 5:32 pm
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.

Re: Wide 'W'

Posted: Sun Jan 26, 2014 8:55 am
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.