int unicodeGetXRanges(char *utf8, int utf8Length, int *resultPtr, int resultLength) {
	int w, h, offsetX, offsetY;
	int count, ch, i, j;
	PangoRectangle rect;

	count = unicodeLength(utf8, utf8Length);
	if (resultLength < (2 * count)) return -1;

	if (cachedLayout == NULL) {
		cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1);
		cairo_t *cr = cairo_create(surface);
		cachedLayout = pango_cairo_create_layout(cr);
	}

	computeLayout(cachedLayout, utf8, utf8Length, &w, &h, &offsetX, &offsetY, NULL);

	i = j = 0;
	while ((i < utf8Length) && (j < (resultLength - 1))) {
		pango_layout_index_to_pos(cachedLayout, i, &rect);
		ch = utf8[i];
		if ((ch & 0xE0) == 0xC0) i += 2;
		else if ((ch & 0xF0) == 0xE0) i += 3;
		else if ((ch & 0xF8) == 0xF0) i += 4;
		else i += 1;
		resultPtr[j] = PANGO_PIXELS(rect.x);
		resultPtr[j + 1] = PANGO_PIXELS(rect.x + rect.width);
		j += 2;
	}

	return count;
}
Пример #2
0
QRect TalkablePainter::checkboxRect()
{
    ItemRect = Option.rect;
    ItemRect.adjust(HFrameMargin, VFrameMargin, -HFrameMargin, -VFrameMargin);

    computeLayout();
    return CheckboxRect;
}
void unicodeMeasureString(char *utf8, int utf8Length, int *wPtr, int *hPtr) {
	int offsetX, offsetY;

	if (cachedLayout == NULL) {
		cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1);
		cairo_t *cr = cairo_create(surface);
		cachedLayout = pango_cairo_create_layout(cr);
	}

	computeLayout(cachedLayout, utf8, utf8Length, wPtr, hPtr, &offsetX, &offsetY, NULL);
}
Пример #4
0
Vector2i AdvancedGridLayout::preferredSize(NVGcontext *ctx, const Widget *widget) const {
    /* Compute minimum row / column sizes */
    std::vector<int> grid[2];
    computeLayout(ctx, widget, grid);

    Vector2i size(
        std::accumulate(grid[0].begin(), grid[0].end(), 0),
        std::accumulate(grid[1].begin(), grid[1].end(), 0));

    Vector2i extra = Vector2i::Constant(2 * mMargin);
    if (dynamic_cast<const Window *>(widget))
        extra[1] += widget->theme()->mWindowHeaderHeight - mMargin/2;

    return size+extra;
}
Пример #5
0
void AdvancedGridLayout::performLayout(NVGcontext *ctx, Widget *widget) const {
    std::vector<int> grid[2];
    computeLayout(ctx, widget, grid);

    grid[0].insert(grid[0].begin(), mMargin);
    if (dynamic_cast<const Window *>(widget))
        grid[1].insert(grid[1].begin(), widget->theme()->mWindowHeaderHeight + mMargin/2);
    else
        grid[1].insert(grid[1].begin(), mMargin);

    for (int axis=0; axis<2; ++axis) {
        for (size_t i=1; i<grid[axis].size(); ++i)
            grid[axis][i] += grid[axis][i-1];

        for (Widget *w : widget->children()) {
            Anchor anchor = this->anchor(w);
            if (!w->visible())
                continue;

            int itemPos = grid[axis][anchor.pos[axis]];
            int cellSize  = grid[axis][anchor.pos[axis] + anchor.size[axis]] - itemPos;
            int ps = w->preferredSize(ctx)[axis], fs = w->fixedSize()[axis];
            int targetSize = fs ? fs : ps;

            switch (anchor.align[axis]) {
                case Alignment::Minimum:
                    break;
                case Alignment::Middle:
                    itemPos += (cellSize - targetSize) / 2;
                    break;
                case Alignment::Maximum:
                    itemPos += cellSize - targetSize;
                    break;
                case Alignment::Fill:
                    targetSize = fs ? fs : cellSize;
                    break;
            }

            Vector2i pos = w->position(), size = w->size();
            pos[axis] = itemPos;
            size[axis] = targetSize;
            w->setPosition(pos);
            w->setSize(size);
            w->performLayout(ctx);
        }
    }
}
Пример #6
0
Vector2i GridLayout::preferredSize(NVGcontext *ctx,
                                   const Widget *widget) const {
    /* Compute minimum row / column sizes */
    std::vector<int> grid[2];
    computeLayout(ctx, widget, grid);

    Vector2i size(
        2*mMargin + std::accumulate(grid[0].begin(), grid[0].end(), 0)
         + std::max((int) grid[0].size() - 1, 0) * mSpacing[0],
        2*mMargin + std::accumulate(grid[1].begin(), grid[1].end(), 0)
         + std::max((int) grid[1].size() - 1, 0) * mSpacing[1]
    );

    if (dynamic_cast<const Window *>(widget))
        size[1] += widget->theme()->mWindowHeaderHeight - mMargin/2;

    return size;
}
Пример #7
0
int TalkablePainter::height()
{
    ItemRect = QRect(0, 0, 0, 20);

    const QHeaderView *const header = Widget->header();
    if (header)
        ItemRect.setWidth(header->sectionSize(0) - itemIndentation());

    ItemRect.adjust(HFrameMargin, VFrameMargin, -HFrameMargin, -VFrameMargin);

    computeLayout();

    QRect wholeRect = CheckboxRect;
    wholeRect |= IconRect;
    wholeRect |= AvatarRect;
    wholeRect |= IdentityNameRect;
    wholeRect |= NameRect;
    wholeRect |= DescriptionRect;

    return wholeRect.height() + 2 * VFrameMargin;
}
Пример #8
0
void TalkablePainter::paint(QPainter *painter)
{
    ItemRect = Option.rect;
    ItemRect.adjust(HFrameMargin, VFrameMargin, -HFrameMargin, -VFrameMargin);

    computeLayout();

    fixColors();

    // some bit of broken logic
    if (drawSelected() || drawDisabled() || !Configuration->useConfigurationColors())
        painter->setPen(textColor());
    else
    {
        Buddy buddy = Index.data(BuddyRole).value<Buddy>();
        Contact contact = Index.data(ContactRole).value<Contact>();
        if (buddy.isBlocked() || contact.isBlocking())
            painter->setPen(QColor(255, 0, 0));
        else
            painter->setPen(Configuration->fontColor());
    }

    paintCheckbox(painter);
    paintIcon(painter);
    paintAvatar(painter);
    paintIdentityName(painter);
    paintName(painter);
    paintDescription(painter);

    /*
    paintDebugRect(painter, ItemRect, QColor(255, 0, 0));
    paintDebugRect(painter, CheckboxRect, QColor(255, 255, 0));
    paintDebugRect(painter, IconRect, QColor(0, 255, 0));
    paintDebugRect(painter, AvatarRect, QColor(0, 0, 255));
    paintDebugRect(painter, IdentityNameRect, QColor(255, 0, 255));
    paintDebugRect(painter, NameRect, QColor(0, 255, 255));
    paintDebugRect(painter, DescriptionRect, QColor(0, 0, 0));
    */
}
void unicodeDrawString(char *utf8, int utf8Length, int *wPtr, int *hPtr, unsigned int *bitmapPtr) {
	int w = *wPtr;
	int h = *hPtr;
	int pixelCount = w * h;
	int offsetX, offsetY;
	unsigned int *pixelPtr, *lastPtr;

	cairo_surface_t *surface = cairo_image_surface_create_for_data((unsigned char *) bitmapPtr, CAIRO_FORMAT_RGB24, w, h, (4 * w));
	cairo_t *cr = cairo_create(surface);
	PangoLayout *layout = pango_cairo_create_layout(cr);

	computeLayout(layout, utf8, utf8Length, wPtr, hPtr, &offsetX, &offsetY, NULL);

	// fill with background color if not transparent
	if (g_bgRGB != 0) {
		cairo_set_source_rgb(cr, g_bgRed / 255.0, g_bgGreen / 255.0, g_bgBlue / 255.0);
		cairo_paint(cr);
	}

	cairo_translate(cr, offsetX, offsetY);
	cairo_set_source_rgb(cr, g_fgRed / 255.0, g_fgGreen / 255.0, g_fgBlue / 255.0);
	pango_cairo_show_layout(cr, layout);

	// map bg color pixels to transparent if so desired
	if (g_bgTransparent) {
		pixelPtr = bitmapPtr;
		lastPtr = pixelPtr + pixelCount;
		while (pixelPtr < lastPtr) {
			if (*pixelPtr == g_bgRGB) *pixelPtr = 0;
			pixelPtr++;
		}
	}

	g_object_unref(layout);
	cairo_destroy(cr);
	cairo_surface_destroy(surface);
}
Пример #10
0
void XWidget::reLayout()
{
	computeLayout();
	onPaint(X_PAINT);
	showWidget();
}
Пример #11
0
// Build the scaffolds.
// The algorithm first finds the connected components of the graph then
// all the terminal vertices of each component. It then searches the
// components starting from the terminals for a walk that maximizes
// the size of the contigs in the primary scaffold.
void ScaffoldAlgorithms::makeScaffolds(ScaffoldGraph* pGraph)
{
    // Set every edge to be colored black
    // Edges that are kept in the scaffold will be colored white
    pGraph->setEdgeColors(GC_BLACK);

    ScaffoldConnectedComponents connectedComponents;
    ScaffoldAlgorithms::connectedComponents(pGraph, connectedComponents);

    // Iterate over each connected component and linearize the scaffolds
    for(size_t i = 0; i < connectedComponents.size(); ++i)
    {
        // Discover the terminal vertices in the component
        ScaffoldVertexPtrVector& component = connectedComponents[i];

        if(component.size() == 1)
            continue; //nothing to do

        //
        ScaffoldVertexPtrVector terminalVertices;
        computeTerminalsForConnectedComponent(component, terminalVertices);

        if(terminalVertices.empty())
        {
            std::cerr << "Warning: scaffold component of size " << component.size() << " does not have a terminal vertex. Skipping\n";
            continue;
        }
        // Construct a scaffold layout for each terminal vertex of the component
        // We select the layout that contains the greatest amount of sequence as
        // the initial layout of the scaffold
        size_t bestLayoutBases = 0;
        ScaffoldWalk bestWalk(NULL);

        for(size_t j = 0; j < terminalVertices.size(); j++)
        {
            ScaffoldWalkVector layouts;
            computeLayout(terminalVertices[j], layouts);

            for(size_t k = 0; k < layouts.size(); ++k)
            {
                size_t layoutSum = layouts[k].getContigLengthSum();

                if(layoutSum > bestLayoutBases)
                {
                    bestLayoutBases = layoutSum;
                    bestWalk = layouts[k];
                }
            }
        }

        // Ensure a valid layout is chosen
        assert(bestLayoutBases > 0 && bestWalk.getStartVertex() != NULL);

        // Remove every edge that is not a part of the chosen walk
        // Since every edge in the graph was initially colored black,
        // we color the kept edges white then remove every black edge
        // in a single pass later
        ScaffoldEdgePtrVector keptEdges = bestWalk.getEdges();
        for(size_t j = 0; j < keptEdges.size(); ++j)
        {
            keptEdges[j]->setColor(GC_WHITE);
            keptEdges[j]->getTwin()->setColor(GC_WHITE);
        }
    }

    // Remove all edges that aren't on a chosen layouts
    pGraph->deleteEdgesByColor(GC_BLACK);
}
Пример #12
0
void GridLayout::performLayout(NVGcontext *ctx, Widget *widget) const {
    Vector2i fs_w = widget->fixedSize();
    Vector2i containerSize(
        fs_w[0] ? fs_w[0] : widget->width(),
        fs_w[1] ? fs_w[1] : widget->height()
    );

    /* Compute minimum row / column sizes */
    std::vector<int> grid[2];
    computeLayout(ctx, widget, grid);
    int dim[2] = { (int) grid[0].size(), (int) grid[1].size() };

    Vector2i extra = Vector2i::Zero();
    if (dynamic_cast<Window *>(widget))
        extra[1] += widget->theme()->mWindowHeaderHeight - mMargin / 2;

    /* Strech to size provided by \c widget */
    for (int i = 0; i < 2; i++) {
        int gridSize = 2 * mMargin + extra[i];
        for (int s : grid[i]) {
            gridSize += s;
            if (i+1 < dim[i])
                gridSize += mSpacing[i];
        }

        if (gridSize < containerSize[i]) {
            /* Re-distribute remaining space evenly */
            int gap = containerSize[i] - gridSize;
            int g = gap / dim[i];
            int rest = gap - g * dim[i];
            for (int j = 0; j < dim[i]; ++j)
                grid[i][j] += g;
            for (int j = 0; rest > 0 && j < dim[i]; --rest, ++j)
                grid[i][j] += 1;
        }
    }

    int axis1 = (int) mOrientation, axis2 = (axis1 + 1) % 2;
    Vector2i start = Vector2i::Constant(mMargin) + extra;

    size_t numChildren = widget->children().size();
    size_t child = 0;

    Vector2i pos = start;
    for (int i2 = 0; i2 < dim[axis2]; i2++) {
        pos[axis1] = start[axis1];
        for (int i1 = 0; i1 < dim[axis1]; i1++) {
            Widget *w = nullptr;
            do {
                if (child >= numChildren)
                    return;
                w = widget->children()[child++];
            } while (!w->visible());

            Vector2i ps = w->preferredSize(ctx);
            Vector2i fs = w->fixedSize();
            Vector2i targetSize(
                fs[0] ? fs[0] : ps[0],
                fs[1] ? fs[1] : ps[1]
            );

            Vector2i itemPos(pos);
            for (int j = 0; j < 2; j++) {
                int axis = (axis1 + j) % 2;
                int item = j == 0 ? i1 : i2;
                Alignment align = alignment(axis, item);

                switch (align) {
                    case Alignment::Minimum:
                        break;
                    case Alignment::Middle:
                        itemPos[axis] += (grid[axis][item] - targetSize[axis]) / 2;
                        break;
                    case Alignment::Maximum:
                        itemPos[axis] += grid[axis][item] - targetSize[axis];
                        break;
                    case Alignment::Fill:
                        targetSize[axis] = fs[axis] ? fs[axis] : grid[axis][item];
                        break;
                }
            }
            w->setPosition(itemPos);
            w->setSize(targetSize);
            w->performLayout(ctx);
            pos[axis1] += grid[axis1][i1] + mSpacing[axis1];
        }
        pos[axis2] += grid[axis2][i2] + mSpacing[axis2];
    }
}