Exemplo n.º 1
0
void
vsBuiltInFont::CreateStringInDisplayList(vsDisplayList *list, const vsString &string, float size, float capSize, JustificationType j, float maxWidth)
{
	if ( maxWidth > 0.f )
	{
		WrapLine(string, size, capSize, j, maxWidth);

		float lineHeight = capSize;
		float lineMargin = capSize * c_lineMarginFactor;

//		float baseOffsetDown = lineHeight * (m_wrappedLineCount * 0.5f);
		float totalHeight = (lineHeight * s_wrappedLineCount) + (lineMargin * (s_wrappedLineCount-1));
		float baseOffsetDown = totalHeight * 0.5f;
		float topLinePosition = baseOffsetDown - totalHeight + lineHeight;

//		float halfTotalHeight = totalHeight * 0.5f;
		list->Clear();

		vsVector2D offset(0.f,topLinePosition);

		for ( int i = 0; i < s_wrappedLineCount; i++ )
		{
			offset.y = topLinePosition + (i*(lineHeight+lineMargin));
			s_tempFontList.Clear();
			BuildDisplayListFromString( &s_tempFontList, s_wrappedLine[i].c_str(), size, capSize, j, offset );
			list->Append(s_tempFontList);
		}
		vsVector2D tl,br;
		list->GetBoundingBox(tl,br);
		/*
		float height = br.y-tl.y;
		list->Clear();

		for ( int i = 0; i < m_wrappedLineCount; i++ )
		{
			offset.Set(0.f,lineHeight*i - 0.5f*height);
			s_tempFontList.Clear();
			BuildDisplayListFromString( &s_tempFontList, m_wrappedLine[i].c_str(), size, capSize, j, offset );
			list->Append(s_tempFontList);
		}*/
	}
	else
	{
		float lineHeight = capSize;
		float totalHeight = lineHeight;
		float baseOffsetDown = totalHeight * 0.5f;
		float topLinePosition = baseOffsetDown - totalHeight + lineHeight;
		list->Clear();

		vsVector2D offset(0.f,topLinePosition);

		list->Clear();
		BuildDisplayListFromString( list, string.c_str(), size, capSize, j, offset );
	}
}
Exemplo n.º 2
0
bool TextFormatter::FormatFwd(CFDC& dc, FilePos start)
{
    AdjustPos(start); // just to be safe
    if (start.para >= m_tf->Length(start.docid))
        return false; // at eof
    m_lines.RemoveAll();
    m_top = start;
    bool header = true;
    for (int page = 0; page < m_pages; ++page)
    {
        int h = 0;
        int beg = m_lines.GetSize();
        while (h < m_height && start.para < m_tf->Length(start.docid))
        {
            Paragraph para(m_tf->GetParagraph(start.docid, start.para));
            bool empty = para.len == 0 || para.len == 1 && para.str[0] == _T(' ');
            if (h == 0 && empty)
            {
                start.off = para.len;
                AdjustPos(start);
                continue;
            }
            if (para.flags & Paragraph::header)
            {
                if (!header)
                    break;
            }
            else
                if (!empty && !(para.flags & Paragraph::image))
                    header = false;
            int lh = WrapLine(dc, para, start, m_lines, h, m_height - h);
            if (lh < 0)
                break;
            AdjustPos(start);
            h += lh;
        }
        m_pagelen.SetAtGrow(page, m_lines.GetSize() - beg);
    }
    m_bot = start;
    Highlight();
    // add one dummy line always
    Line l;
    l.pos = m_bot;
    m_lines.Add(l);
    return true;
}
Exemplo n.º 3
0
void TextFormatter::FormatPlainText(CFDC& dc,
    int& width, int& height,
    int fontsize,
    const wchar_t *text, int len,
    LineArray& lines)
{
    lines.RemoveAll();

    int save_width = m_width;
    bool save_justified = m_justified;
    m_width = width;
    m_justified = false;

    const wchar_t *top = text + len;

    Attr attr;
    attr.wa = 0;
    attr.fsize = fontsize;

    int curh = 0;

    while (text < top && curh < height)
    {
        const wchar_t *p_end = text;
        while (p_end < top && *p_end != '\r' && *p_end != '\n')
            ++p_end;
        Paragraph p(p_end - text);
        memcpy(p.str, text, (p_end - text)*sizeof(wchar_t));
        for (int i = 0; i < p.cflags.size(); ++i)
            p.cflags[i].wa = attr.wa;
        p.findent = 3; // XXX
        int last = lines.GetSize();
        FilePos fp = FilePos();
        int lh = WrapLine(dc, p, fp, lines, curh, height - curh);
        if (lh < 0)
        {
            // it still might add something
            while (last < lines.GetSize())
                curh += lines[last++].height;
            break;
        }
        curh += lh;
        while (p_end < top && (*p_end == '\r' || *p_end == '\n'))
            ++p_end;
        text = p_end;
    }

    m_width = save_width;
    m_justified = save_justified;

    // deduct ispace
    int min_ispace = -1, max_width = 0;
    for (int i = 0; i < lines.GetSize(); ++i)
    {
        const Line& ll = lines[i];
        int w = 0;
        for (int j = 0; j < ll.dx.size(); ++j)
            w += ll.dx[j];
        w += ll.ispace;
        if (max_width < w)
            max_width = w;
        if (min_ispace<0 || min_ispace>ll.ispace)
            min_ispace = ll.ispace;
    }

    if (min_ispace > 0)
    {
        for (int i = 0; i < lines.GetSize(); ++i)
            lines[i].ispace -= min_ispace;
        max_width -= min_ispace;
    }

    height = curh;
    width = max_width;
}
Exemplo n.º 4
0
bool TextFormatter::FormatBack(CFDC& dc, FilePos start, FilePos prev_top)
{
    AdjustPos(start, true);
    if (start.para == 0 && start.off == 0)
        return false; // at the top
    m_lines.RemoveAll();
    m_bot = start;
    for (int page = m_pages - 1; page >= 0; --page)
    {
        LineArray tmp;
        FilePos pos = start;
        int h = 0;
        // while there are still paragrahs before
        while (h < m_height && (pos.para>0 || pos.off > 0))
        {
            // format entire paragraph
            LineArray cp;
            Paragraph para(m_tf->GetParagraph(pos.docid, pos.para));
            if (pos.off < para.len) // double check args
                para.len = pos.off;
            else
                pos.off = para.len;
            FilePos fp = FilePos(pos.para, 0, pos.docid);
            WrapLine(dc, para, fp, cp, 0, 32768);
            // insert the formatted paragraph at start of list
            tmp.InsertAt(0, &cp);
            for (int i = 0; i < cp.GetSize(); ++i)
                h += cp[i].height;
            pos.off = 0;
            AdjustPos(pos, true);
        }
        // delete extra lines
        int j;
        // remove top lines
        for (h = 0, j = tmp.GetUpperBound(); j >= 0 && h + tmp[j].height <= m_height; --j)
            h += tmp[j].height;
        if (j < tmp.GetUpperBound())
        {
            if (j >= 0 && prev_top != 0 && tmp[j + 1].pos >= prev_top)
            {
                --j;
                tmp.RemoveAt(0, j + 1);
                // now remove bottom lines
                for (h = j = 0; j < tmp.GetSize() && h + tmp[j].height <= m_height; ++j)
                    h += tmp[j].height;
                if (j < tmp.GetSize())
                    tmp.RemoveAt(j, tmp.GetSize() - j);
            }
            else
            {
                tmp.RemoveAt(0, j + 1);
            }
        }
        // save lines
        m_lines.InsertAt(0, &tmp);
        m_pagelen.SetAtGrow(page, tmp.GetSize());
        start = m_lines[0].pos;
        if (start.para == 0 && start.off == 0) // we reached the top of file
            return FormatFwd(dc, FilePos(0, 0, start.docid));
    }
    // save positions
    m_top = m_lines[0].pos;
    Highlight();
    // add one dummy line always
    Line l;
    l.pos = m_bot;
    m_lines.Add(l);
    return true;
}
Exemplo n.º 5
0
/*
 * Called when read from service pipe signals
 */
static void
OnService(connection_t *c, UNUSED char *msg)
{
    DWORD err = 0;
    DWORD pid = 0;
    WCHAR *p, *buf, *next;
    DWORD len;
    const WCHAR *prefix = L"IService> ";

    len = wcslen (c->iserv.readbuf);
    if (!len || (buf = wcsdup (c->iserv.readbuf)) == NULL)
        return;

    /* messages from the service are in the format "0x08x\n%s\n%s" */
    if (swscanf (buf, L"0x%08x\n", &err) != 1)
    {
        free (buf);
        return;
    }

    p = buf + 11;
    if (!err && swscanf (p, L"0x%08x\nProcess ID", &pid) == 1 && pid != 0)
    {
        PrintDebug (L"Process ID of openvpn started by IService: %d", pid);
        c->hProcess = OpenProcess (PROCESS_TERMINATE|PROCESS_QUERY_INFORMATION, FALSE, pid);
        if (!c->hProcess)
            PrintDebug (L"Failed to get process handle from pid of openvpn: error = %lu",
                        GetLastError());
        free (buf);
        return;
    }

    while (iswspace(*p)) ++p;

    while (p && *p)
    {
        next = WrapLine (p);
        WriteStatusLog (c, prefix, p, c->manage.connected ? FALSE : TRUE);
        p = next;
    }
    free (buf);

    /* Error from iservice before management interface is connected */
    switch (err)
    {
        case 0:
            break;
        case ERROR_STARTUP_DATA:
            WriteStatusLog (c, prefix, L"OpenVPN not started due to previous errors", true);
            c->state = timedout;   /* Force the popup message to include the log file name */
            OnStop (c, NULL);
            break;
        case ERROR_OPENVPN_STARTUP:
            WriteStatusLog (c, prefix, L"Check the log file for details", false);
            c->state = timedout;   /* Force the popup message to include the log file name */
            OnStop(c, NULL);
            break;
        default:
            /* Unknown failure: let management connection timeout */
            break;
    }
}