bool Direct2DLowLevelGraphicsContext::drawTextLayout (const AttributedString& text, const Rectangle<float>& area)
{
    renderingTarget->SetTransform (transformToMatrix (currentState->transform));
    const Direct2DFactories& factories = Direct2DFactories::getInstance();
    Rectangle<float>  newArea(area.getX(), area.getY(), area.getWidth(), area.getHeight());
    DirectWriteTypeLayout::drawToD2DContext (text, newArea, renderingTarget, factories.directWriteFactory, factories.d2dFactory, factories.systemFonts);
    return true;
}
Exemplo n.º 2
0
void PageItem_Table::mergeCells(int row, int column, int numRows, int numCols)
{
	ASSERT_VALID();

	if (!validCell(row, column) || !validCell(row + numRows - 1, column + numCols - 1))
		return;

	CellArea newArea(row, column, numCols, numRows);

	// Unite intersecting areas.
	QMutableListIterator<CellArea> areaIt(m_cellAreas);
	while (areaIt.hasNext())
	{
		CellArea oldArea = areaIt.next();
		if (newArea.intersects(oldArea))
		{
			// The two areas intersect, so unite them.
			newArea = newArea.united(oldArea);

			// Reset row/column span of old spanning cell, then remove old area.
			TableCell oldSpanningCell = cellAt(oldArea.row(), oldArea.column());
			oldSpanningCell.setRowSpan(1);
			oldSpanningCell.setColumnSpan(1);
			areaIt.remove();
		}
	}

	// Set row/column span of new spanning cell, and add new area.
	TableCell newSpanningCell = cellAt(newArea.row(), newArea.column());
	newSpanningCell.setRowSpan(newArea.height());
	newSpanningCell.setColumnSpan(newArea.width());
	m_cellAreas.append(newArea);

	// Update cells. TODO: Not for entire table.
	updateCells();

	// If merged area covers active position, move to the spanning cell.
	if (newArea.contains(m_activeRow, m_activeColumn))
		moveTo(newSpanningCell);

	// Remove all cells covered by the merged area from the selection.
	QMutableSetIterator<TableCell> cellIt(m_selection);
	while (cellIt.hasNext())
	{
		TableCell cell = cellIt.next();
		if (newArea.contains(cell.row(), cell.column()) &&
			!(cell.row() == newArea.row() && cell.column() == newArea.column()))
			cellIt.remove();
	}

	emit changed();

	ASSERT_VALID();
}
VOID ReallocAfter(ADDRINT mallocStartAddr, THREADID tid)
{
	ThreadLocalStorage* tls = getTLS(tid);
	ADDRINT previousAddress = tls->nextReallocAddr;
	ADDRINT newSize = tls->nextReallocSize;

	//if previous address is NULL, this is the same as malloc
	if (previousAddress == 0)
	{
		tls->nextMallocSize = tls->nextReallocSize;
		tls->nextReallocAddr = 0;
		tls->nextReallocSize = 0;
		MallocAfter(mallocStartAddr, tid);
		return;
	}

	const MemoryArea& prevArea = findMemoryArea(mallocStartAddr);
	MemoryArea newArea(tid, mallocStartAddr, mallocStartAddr + newSize);

	ADDRINT prevSize = prevArea.to - prevArea.from;

	// Realloc gives the same address as previos realloc(or malloc,calloc)
	if (prevArea.from == mallocStartAddr)
	{
		//eger yeni yer daha kucuk ise, eskiden bizim olan aradaki yerleri free edelim
		if (newSize < prevSize)
		{
			freeMemoryAddress(mallocStartAddr + newSize,
			                  mallocStartAddr + prevSize, tid);
		}
	}
	else
	{
		if (newSize < prevSize)
		{
			moveMemoryAddresses(previousAddress, mallocStartAddr, newSize, tid);
			freeMemoryAddress(previousAddress + newSize,
			                  previousAddress + prevSize, tid);
		}
		else
		{
			moveMemoryAddresses(previousAddress, mallocStartAddr, prevSize,
			                    tid);
			freeMemoryAddress(previousAddress, previousAddress + prevSize, tid);
		}
	}

	GetLock(&memorySetLock, tid);
	memorySet.insert(newArea);
	memorySet.erase(prevArea);
	ReleaseLock(&memorySetLock);
}
VOID MallocAfter(ADDRINT mallocStartAddr, THREADID tid)
{
	ThreadLocalStorage* tls = getTLS(tid);
	ADDRINT mallocEndAddr = tls->nextMallocSize + mallocStartAddr;
	tls->nextMallocSize = 0;

	MemoryArea newArea(tid, mallocStartAddr, mallocEndAddr);

	GetLock(&memorySetLock, tid);
	MemorySetItr overlaps = smallestOverlappingMemoryArea(newArea);

	if (overlaps != memorySet.end())
	{
		// has overlapping elements
	}

	ReleaseLock(&memorySetLock);
}
Exemplo n.º 5
0
BBitmap* TRotationEffect::TransformBitmap(int32 time, const BBitmap* source,
		const TCuePosition& pos, EffectQuality quality)
{
	//	Get rotation value at 'time'
	float 	rotateDegrees = RotationDegrees(time);
	//	Make sure we even need to rotate
	if (rotateDegrees == 0)
		return 0;
	
	//	Calculate bounds rect to composite into
	BRect drawRect = source->Bounds();
			
	//	Calculate source dimensions
	const int32 srcColumns  = drawRect.Width();
	const int32 srcRows 	= drawRect.Height();

	//	Calculate rotation angle
    double angle 	= ((double) 3.14159265 / (double) 180.0) * (double) rotateDegrees;	// convert to RADs
	
	//	Calculate angle minus 90 degrees
	double	angle2 	= 1.570796327 - angle;
    
    //	Calculate sine and cosine of rotation angle
	double 	cosine 	= cos(angle);
	double 	sine	= sin(angle);

	// 	Calculate destination dimensions
	const int32 dstColumns 	= srcRows * fabs( cos(angle2) ) + srcColumns * fabs(cosine); 
	const int32 dstRows 	= srcRows * fabs( cosine ) + srcColumns * fabs( cos(angle2)); 

	//	Calculate new bitmap bounds
	BRect newArea(0, 0, dstColumns, dstRows);	
	
	//	Calculate draw pt based on center of bitmap
	int32 areaCenterX = newArea.Width()  / 2;
	int32 areaCenterY = newArea.Height() / 2;

	//	Get center point of drawRect
	int32 drawCenterX = drawRect.Width()  / 2;
	int32 drawCenterY = drawRect.Height() / 2;

	//	Calculate difference between center points
	int32 diffX = areaCenterX - drawCenterX;
	int32 diffY = areaCenterY - drawCenterY;

	//	Offset drawRect and set up drawPt
	drawRect.OffsetBy(-diffX, -diffY);
			
	//	Offset rect to proper drawing coordinates
	newArea.OffsetTo(drawRect.left, drawRect.top);		
	
	BBitmap* rotated = new BBitmap( newArea, B_RGB32, true, false);
				
	//	Do rotation
	switch(quality) 
	{
		case kWireframeQuality:
		case kPreviewQuality:
		case kBetterQuality:
		case kBestQuality: 
		{
			//	Create composite bitmap
			RotateBitmapNN(source, rotated, rotateDegrees, pos.Registration());
			break;
		}
		
		default:
			TRESPASS();
			delete rotated;
			rotated = 0;
			break;
	}		

	return rotated;
}
Exemplo n.º 6
0
bool AreaAllocator::Allocate(int width, int height, int& x, int& y)
{
    if (width < 0)
        width = 0;
    if (height < 0)
        height = 0;
    
    PODVector<IntRect>::Iterator best;
    int bestFreeArea;
    
    for(;;)
    {
        best = freeAreas_.End();
        bestFreeArea = M_MAX_INT;
        for (PODVector<IntRect>::Iterator i = freeAreas_.Begin(); i != freeAreas_.End(); ++i)
        {
            int freeWidth = i->Width();
            int freeHeight = i->Height();
            
            if (freeWidth >= width && freeHeight >= height)
            {
                // Calculate rank for free area. Lower is better
                int freeArea = freeWidth * freeHeight;
                
                if (freeArea < bestFreeArea)
                {
                    best = i;
                    bestFreeArea = freeArea;
                }
            }
        }
        
        if (best == freeAreas_.End())
        {
            if (doubleWidth_ && size_.x_ < maxSize_.x_)
            {
                int oldWidth = size_.x_;
                size_.x_ <<= 1;
                // If no allocations yet, simply expand the single free area
                IntRect& first = freeAreas_.Front();
                if (freeAreas_.Size() == 1 && first.left_ == 0 && first.top_ == 0 && first.right_ == oldWidth && first.bottom_ == size_.y_)
                    first.right_ = size_.x_;
                else
                {
                    IntRect newArea(oldWidth, 0, size_.x_, size_.y_);
                    freeAreas_.Push(newArea);
                }
            }
            else if (!doubleWidth_ && size_.y_ < maxSize_.y_)
            {
                int oldHeight = size_.y_;
                size_.y_ <<= 1;
                // If no allocations yet, simply expand the single free area
                IntRect& first = freeAreas_.Front();
                if (freeAreas_.Size() == 1 && first.left_ == 0 && first.top_ == 0 && first.right_ == size_.x_ && first.bottom_ == oldHeight)
                    first.bottom_ = size_.y_;
                else
                {
                    IntRect newArea(0, oldHeight, size_.x_, size_.y_);
                    freeAreas_.Push(newArea);
                }
            }
            else
                return false;
            
            doubleWidth_ = !doubleWidth_;
        }
        else
            break;
    }
    
    IntRect reserved(best->left_, best->top_, best->left_ + width, best->top_ + height);
    x = best->left_;
    y = best->top_;
    
    if (fastMode_)
    {
        // Reserve the area by splitting up the remaining free area
        best->left_ = reserved.right_;
        if (best->Height() > 2 * height || height >= size_.y_ / 2)
        {
            IntRect splitArea(reserved.left_, reserved.bottom_, best->right_, best->bottom_);
            best->bottom_ = reserved.bottom_;
            freeAreas_.Push(splitArea);
        }
    }
    else
    {
        // Remove the reserved area from all free areas
        for (unsigned i = 0; i < freeAreas_.Size();)
        {
            if (SplitRect(freeAreas_[i], reserved))
                freeAreas_.Erase(i);
            else
                ++i;
        }
        
        Cleanup();
    }
    
    return true;
}
Exemplo n.º 7
0
bool AreaAllocator::Allocate(int width, int height, int& x, int& y)
{
    if (width < 0)
        width = 0;
    if (height < 0)
        height = 0;
    
    PODVector<IntRect>::Iterator best = freeAreas_.End();
    int bestFreeArea = M_MAX_INT;
    
    for(;;)
    {
        for (PODVector<IntRect>::Iterator i = freeAreas_.Begin(); i != freeAreas_.End(); ++i)
        {
            int freeWidth = i->Width();
            int freeHeight = i->Height();
            
            if (freeWidth >= width && freeHeight >= height)
            {
                // Calculate rank for free area. Lower is better
                int freeArea = freeWidth * freeHeight;
                
                if (freeArea < bestFreeArea)
                {
                    best = i;
                    bestFreeArea = freeArea;
                }
            }
        }
        
        if (best == freeAreas_.End())
        {
            if (doubleWidth_ && size_.x_ < maxSize_.x_)
            {
                int oldWidth = size_.x_;
                size_.x_ <<= 1;
                IntRect newArea(oldWidth, 0, size_.x_, size_.y_);
                freeAreas_.Push(newArea);
            }
            else if (!doubleWidth_ && size_.y_ < maxSize_.y_)
            {
                int oldHeight = size_.y_;
                size_.y_ <<= 1;
                IntRect newArea(0, oldHeight, size_.x_, size_.y_);
                freeAreas_.Push(newArea);
            }
            else
                return false;
            
            doubleWidth_ = !doubleWidth_;
        }
        else
            break;
    }
    
    IntRect reserved(best->left_, best->top_, best->left_ + width, best->top_ + height);
    x = best->left_;
    y = best->top_;
    
    // Reserve the area by splitting up the remaining free area
    best->left_ = reserved.right_;
    if (best->Height() > 2 * height)
    {
        IntRect splitArea(reserved.left_, reserved.bottom_, best->right_, best->bottom_);
        best->bottom_ = reserved.bottom_;
        freeAreas_.Push(splitArea);
    }

    return true;
}