示例#1
0
    void CLineImpl::Prepare(
        IZ_UINT8* dst,
        IZ_UINT pitch,
        IZ_UINT ascent,
        IFontHost* host)
    {
        IZ_UINT code = 0;

        CUString string;
        string.Init(m_Encode, m_Text, m_Bytes);

        string.BeginIter();

        IZ_UINT x = 0;

        for (;;)
        {
            if (m_FontHost->GetEncodeType() == E_FONT_CHAR_ENCODE_UNICODE)
            {
                code = string.GetNextAsUnicode();
            }
            else
            {
                code = string.GetNext();
            }

            if (code == 0)
            {
                break;
            }

            IZ_UINT id = m_FontHost->GetGlyphID(code);

            SGlyphMetrics metrics;

            if (m_FontHost->GetGlyphMetricsByID(id, metrics))
            {
                x = this->CopyImage(
                    id,
                    dst,
                    x,
                    pitch,
                    ascent);
            }
            else
            {
                // TODO
            }
        }

        string.EndIter();
    }
示例#2
0
    IZ_UINT CLineImpl::GetLineWidth()
    {
        if (m_Text == IZ_NULL)
        {
            return 0;
        }

        CUString string;
        string.Init(m_Encode, m_Text, m_Bytes);

        IZ_UINT width = 0;
        IZ_UINT code = 0;

        string.BeginIter();

        for (;;)
        {
            if (m_FontHost->GetEncodeType() == E_FONT_CHAR_ENCODE_UNICODE)
            {
                code = string.GetNextAsUnicode();
            }
            else
            {
                code = string.GetNext();
            }

            if (code == 0)
            {
                break;
            }

            SGlyphMetrics metrics;

            if (m_FontHost->GetGlyphMetricsByCode(code, metrics))
            {
                width += metrics.advance;
            }
            else
            {
                // TODO
            }
        }

        string.EndIter();

        return width;
    }
示例#3
0
    IZ_BOOL CParagraphGroupImpl::Init(
        IFontHost* host,
        CUString& str, 
        void* userData)
    {
        SAFE_REPLACE(m_FontHost, host);

        m_LineHeight = m_FontHost->GetPixelSize();
        m_Ascent = m_FontHost->GetAscender();

        IZ_UINT prev = 0;
        IZ_UINT code = 0;

        IZ_BOOL isSeparated = IZ_FALSE;

        const IZ_UINT8* start = str.GetTextPtr();
        IZ_UINT lastPos = 1;

        str.BeginIter();

        for (;;)
        {
            if (isSeparated)
            {
                start = str.GetIterPtr();

                isSeparated = IZ_FALSE;
            }

            code = str.GetNext();

            if (prev == CH_CR && code == CH_LF)
            {
                // skip
                code = str.GetNext();
            }

            prev = code;

            if (_IsSeparator(code) || code == 0)
            {
                IZ_UINT pos = static_cast<IZ_UINT>(str.GetIterDistance());
                IZ_UINT bytes = pos - lastPos;
                lastPos = pos;

                CParagraph* paragraph = CParagraphImpl::CreateParagraph(
                    m_Allocator,
                    host,
                    str.GetCharCode(),
                    start,
                    bytes,
                    userData);

                AddParagraph(paragraph);

                if (code == 0)
                {
                    break;
                }
                else
                {
                    isSeparated = IZ_TRUE;
                }
            }
        }

        str.EndIter();

        return IZ_TRUE;
    }