Example #1
0
void CFontStyle::InitTable()
{
    int dc = mstrlen(kDefChars);
    f_unit_t *w;

    fEscapementsCount = 2 * dc;
    fEscapements = (EscapementEntry *)calloc(fEscapementsCount, sizeof(EscapementEntry));
    FailNil(fEscapements);

    w = (f_unit_t *)malloc(dc * sizeof(f_unit_t));
    FailNil(w);

    fFont.GetEscapements(kDefChars, mstrlen(kDefChars), w);

    const char *s = kDefChars;

    for (int i = 0; i < dc; i++)
    {
        int cl = mcharlen(s);
        int uc = municode(s);
        int ix = uc % fEscapementsCount;

        while (fEscapements[ix].unicode != 0)
            ix = (ix + 1) % fEscapementsCount;

        fEscapements[ix].unicode = uc;
        fEscapements[ix].escapement = w[i] * fFont.Size();

        s += cl;
    }

    free(w);
} /* CFontStyle::InitTable */
Example #2
0
f_unit_t CFontStyle::operator[](const char *s)
{
    int unicode = municode(s);

    {
        StBenaphore lock(&fLock);

        int i = unicode % fEscapementsCount, j = i - 1;
        if (j < 0) j+= fEscapementsCount;

        ASSERT(j >= 0);
        ASSERT(j < fEscapementsCount);

        while (true)
        {
            ASSERT(i >= 0);
            ASSERT(i < fEscapementsCount);

            if (fEscapements[i].unicode == unicode)
                return fEscapements[i].escapement;

            if (fEscapements[i].unicode == 0)
            {
                float w[1];
                char buf[10];
                int cl = mcharlen(s);

                strncpy(buf, s, cl);
                buf[cl] = 0;

                fFont.GetEscapements(buf, 1, w);
                w[0] *= fFont.Size();

                fEscapements[i].unicode = unicode;
                fEscapements[i].escapement = w[0];

                fCharCount++;

                if (fCharCount > fEscapementsCount / 2)
                    ReHash();

                return fEscapements[i].escapement;
            }

            if (i == j) {
                break;
            }

            i = (i + 1) % fEscapementsCount;
        }

        ReHash();

//		printf("recursion for %d\n", unicode);
    }

    return operator[](s);
} /* CFontStyle::operator[] */
Example #3
0
void PTextBuffer::CharInfo(int32 offset, int32& unicode, int32& len) const
{
	ASSERT(offset >= 0);
//	ASSERT(index <= fLogicalSize);

	if (offset >= fLogicalSize || offset < 0)
	{
		unicode = 0;
		len = 1;
	}
	else
	{
		char b[8];
		Copy(b, offset, std::min((int32)7, fLogicalSize - offset));
		b[7] = 0;

		len = mcharlen(b);
		unicode = municode(b);
	}
} /* PTextBuffer::CharInfo */