os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgditext.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgditext.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,818 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "swdirectgdiengine.h"
1.20 +#include <bitdrawinterfaceid.h>
1.21 +#include <bmalphablend.h>
1.22 +
1.23 +/**
1.24 +@see MDirectGdiEngine::SetFont()
1.25 +*/
1.26 +void CSwDirectGdiEngine::SetFont(TUint32 /*aFontId*/)
1.27 + {
1.28 + // Do nothing.
1.29 + // The SW adapter doesn't need the font ID to index a separate font cache because it uses the standard one.
1.30 + }
1.31 +
1.32 +
1.33 +/**
1.34 +@see MDirectGdiEngine::ResetFont()
1.35 +*/
1.36 +void CSwDirectGdiEngine::ResetFont()
1.37 + {
1.38 + }
1.39 +
1.40 +
1.41 +/**
1.42 +@see MDirectGdiEngine::SetTextShadowColor()
1.43 +*/
1.44 +void CSwDirectGdiEngine::SetTextShadowColor(const TRgb& aColor)
1.45 + {
1.46 + iTextShadowColor = aColor;
1.47 + }
1.48 +
1.49 +/**
1.50 +@see MDirectGdiEngine::BeginDrawGlyph()
1.51 +*/
1.52 +void CSwDirectGdiEngine::BeginDrawGlyph()
1.53 + {
1.54 + }
1.55 +
1.56 +/**
1.57 +@see MDirectGdiEngine::DrawGlyph()
1.58 +@panic DGDIAdapter 56, if an invalid glyph bitmap type is passed in.
1.59 +*/
1.60 +void CSwDirectGdiEngine::DrawGlyph(const TPoint& aScrPos, const TChar /*aChar*/, const TUint8* aGlyphImage,
1.61 + const TGlyphBitmapType aGlyphBitmapType, const TSize& aGlyphImageSize,
1.62 + const TRect& aScrClipRect, const DirectGdi::TGraphicsRotation aRotation)
1.63 + {
1.64 + TPoint pos=aScrPos;
1.65 + pos+=iDrawOrigin;
1.66 + TRect clipRect=aScrClipRect;
1.67 + clipRect.iTl+=iDrawOrigin;
1.68 + clipRect.iBr+=iDrawOrigin;
1.69 + TRect regionRect(0, 0, 0, 0);
1.70 + TInt numRects = iDefaultRegionPtr->Count();
1.71 + for (TInt count = 0; count < numRects; count++)
1.72 + {
1.73 + // Do the clip rects intersect?
1.74 + regionRect = (*iDefaultRegionPtr)[count];
1.75 + if (!regionRect.Intersects(clipRect))
1.76 + {
1.77 + // Nothing to draw
1.78 + continue;
1.79 + }
1.80 + // Clip to intersection of two clip rects
1.81 + regionRect.Intersection(clipRect);
1.82 +
1.83 + if (aRotation == DirectGdi::EGraphicsRotationNone) // Horizontal text
1.84 + {
1.85 + // Do the glyph and the clip rect intersect?
1.86 + TRect glyphRect(pos, aGlyphImageSize);
1.87 + if (!regionRect.Intersects(glyphRect))
1.88 + {
1.89 + // Nothing to draw
1.90 + continue;
1.91 + }
1.92 + // Clip to intersection with glyph bitmap
1.93 + regionRect.Intersection(glyphRect);
1.94 +
1.95 + switch (aGlyphBitmapType)
1.96 + {
1.97 + case EMonochromeGlyphBitmap:
1.98 + {
1.99 + DrawBitmapGlyph(pos, aGlyphImage, aGlyphImageSize, regionRect);
1.100 + break;
1.101 + }
1.102 + case EAntiAliasedGlyphBitmap:
1.103 + {
1.104 + DrawAntiAliasedGlyph(pos, aGlyphImage, aGlyphImageSize, regionRect);
1.105 + break;
1.106 + }
1.107 + case EFourColourBlendGlyphBitmap:
1.108 + {
1.109 + DrawFourColourGlyph(pos, aGlyphImage, aGlyphImageSize, regionRect);
1.110 + break;
1.111 + }
1.112 + default:
1.113 + GRAPHICS_PANIC_ALWAYS(EDirectGdiPanicInvalidGlyphBitmapType);
1.114 + }
1.115 + }
1.116 + else // Vertical text
1.117 + {
1.118 + /*
1.119 + // Do the glyph and the clip rect intersect?
1.120 + TRect glyphRect(aPos, aGlyphImageSize);
1.121 + if (!regionRect.Intersects(glyphRect))
1.122 + {
1.123 + // Nothing to draw
1.124 + continue;
1.125 + }
1.126 + // Clip to intersection with glyph bitmap
1.127 + regionRect.Intersection(glyphRect);
1.128 + */
1.129 +
1.130 + switch (aGlyphBitmapType)
1.131 + {
1.132 + case EMonochromeGlyphBitmap:
1.133 + {
1.134 + DrawRotatedBitmapGlyph(pos, aGlyphImage, aGlyphImageSize, regionRect, aRotation);
1.135 + break;
1.136 + }
1.137 + case EAntiAliasedGlyphBitmap:
1.138 + {
1.139 + DrawRotatedAntiAliasedGlyph(pos, aGlyphImage, aGlyphImageSize, regionRect, aRotation);
1.140 + break;
1.141 + }
1.142 + case EFourColourBlendGlyphBitmap:
1.143 + {
1.144 + DrawRotatedFourColourGlyph(pos, aGlyphImage, aGlyphImageSize, regionRect, aRotation);
1.145 + break;
1.146 + }
1.147 + default:
1.148 + GRAPHICS_PANIC_ALWAYS(EDirectGdiPanicInvalidGlyphBitmapType);
1.149 + }
1.150 + }
1.151 + // Now display it
1.152 + iDrawDevice->UpdateRegion(regionRect);
1.153 + }
1.154 + }
1.155 +
1.156 +/**
1.157 +@see MDirectGdiEngine::EndDrawGlyph()
1.158 +*/
1.159 +void CSwDirectGdiEngine::EndDrawGlyph()
1.160 + {
1.161 + }
1.162 +
1.163 +/**
1.164 +Draw a bitmap glyph.
1.165 +
1.166 +@param aPos Position to start drawing gyph.
1.167 +@param aGlyphImage Pointer to the glyph image data.
1.168 +@param aGlyphImageSize Glyph image size.
1.169 +@param aClipRect Clipping rect.
1.170 +*/
1.171 +void CSwDirectGdiEngine::DrawBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.172 + const TSize& aGlyphImageSize, const TRect& aClipRect)
1.173 + {
1.174 + // aChar parameter not needed because SW implementation uses the default glyph cache
1.175 + // therefore does not need aChar to index its own local cache
1.176 +
1.177 + /*
1.178 + Divert if the character is large.
1.179 + Large is defined as wider than 30 bits (a scan line won't fit in a TInt32)
1.180 + or greater than 32 bits high (because that's the current array size - could be changed).
1.181 + */
1.182 + TInt dataHeight = aGlyphImageSize.iHeight;
1.183 + TInt dataLength = aGlyphImageSize.iWidth;
1.184 + if (dataLength > 30 || dataHeight > 32)
1.185 + {
1.186 + DrawLargeBitmapGlyph(aPos, aGlyphImage, aGlyphImageSize, aClipRect);
1.187 + return;
1.188 + }
1.189 +
1.190 + TInt bitIndex = 0;
1.191 + TInt16 repeatCount = 0;
1.192 + TUint32 binaryData[32];
1.193 + TUint32* binaryDataPtr = binaryData;
1.194 + TUint32* binaryDataPtrLimit;
1.195 + for (TInt glyphLine = 0; glyphLine < dataHeight; glyphLine += repeatCount) // for lines in the glyph bitmap
1.196 + {
1.197 + repeatCount = Load16(aGlyphImage + (bitIndex >> 3));
1.198 + repeatCount >>= bitIndex & 7;
1.199 + TInt multiLineFlag = repeatCount & 1;
1.200 + repeatCount >>= 1;
1.201 + repeatCount &= 0xf;
1.202 + bitIndex += 5;
1.203 + binaryDataPtrLimit = binaryData + glyphLine + repeatCount;
1.204 + if (multiLineFlag)
1.205 + {
1.206 + while (binaryDataPtr < binaryDataPtrLimit)
1.207 + {
1.208 + TInt glyphDataOffsetPtr = TInt(aGlyphImage) + (bitIndex >> 3);
1.209 + TUint32* glyphDataWord = (TUint32*)(glyphDataOffsetPtr & ~3);
1.210 + TInt bitShift = bitIndex & 7;
1.211 + bitShift += (glyphDataOffsetPtr & 3) << 3;
1.212 + *binaryDataPtr = (*glyphDataWord++) >> bitShift;
1.213 + if (bitShift)
1.214 + {
1.215 + *binaryDataPtr |= (*glyphDataWord << (32 - bitShift));
1.216 + }
1.217 + bitIndex += dataLength;
1.218 + binaryDataPtr++;
1.219 + }
1.220 + }
1.221 + else
1.222 + {
1.223 + TInt glyphDataOffsetPtr = TInt(aGlyphImage) + (bitIndex >> 3);
1.224 + TUint32* glyphDataWord = (TUint32*)(glyphDataOffsetPtr & ~3);
1.225 + TInt bitShift = bitIndex & 7;
1.226 + bitShift += (glyphDataOffsetPtr & 3) << 3;
1.227 + TUint32 data = (*glyphDataWord++) >> bitShift;
1.228 + if (bitShift)
1.229 + {
1.230 + data |= (*glyphDataWord << (32 - bitShift));
1.231 + }
1.232 + while (binaryDataPtr < binaryDataPtrLimit)
1.233 + {
1.234 + *binaryDataPtr++ = data;
1.235 + }
1.236 + bitIndex += dataLength;
1.237 + }
1.238 + }
1.239 + TPoint topLeft(aPos);
1.240 + binaryDataPtr = ClipBinaryArray(binaryData, binaryData + dataHeight, dataLength, dataHeight, topLeft, aClipRect);
1.241 + if ((dataLength > 0) && (dataHeight > 0))
1.242 + {
1.243 + iDrawDevice->WriteBinary(topLeft.iX, topLeft.iY, binaryDataPtr, dataLength, dataHeight, iPenColor, GcDrawMode(iDrawMode) );
1.244 + }
1.245 + }
1.246 +
1.247 +
1.248 +/**
1.249 +Draw a large bitmap glyph.
1.250 +
1.251 +@param aPos Position to start drawing gyph.
1.252 +@param aGlyphImage Pointer to the glyph image data.
1.253 +@param aGlyphImageSize Glyph image size.
1.254 +@param aClipRect Clipping rect.
1.255 +*/
1.256 +void CSwDirectGdiEngine::DrawLargeBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.257 + const TSize& aGlyphImageSize, const TRect& aClipRect)
1.258 + {
1.259 + TPoint printPos(aPos);
1.260 + const TInt dataLength = aGlyphImageSize.iWidth;
1.261 + const TInt dataHeight = aGlyphImageSize.iHeight;
1.262 + TInt bitIndex = 0;
1.263 + TInt16 repeatCount = 0;
1.264 + TUint32* scanLineBuffer = iDrawDevice->ScanLineBuffer();
1.265 + const TInt scanLineWords = (iDrawDevice->ScanLineBytes()) << 3;
1.266 + for (TInt glyphLine = 0; glyphLine < dataHeight; glyphLine += repeatCount) // for lines in the glyph bitmap
1.267 + {
1.268 + repeatCount = Load16(aGlyphImage + (bitIndex >> 3));
1.269 + repeatCount >>= bitIndex & 7;
1.270 + const TInt multiLineFlag = repeatCount & 1;
1.271 + repeatCount >>= 1;
1.272 + repeatCount &= 0xf;
1.273 + bitIndex += 5;
1.274 + if (multiLineFlag)
1.275 + {
1.276 + for (TInt currentLine = 0; currentLine < repeatCount; currentLine++)
1.277 + {
1.278 + CopyCharLine(scanLineBuffer, scanLineWords, aGlyphImage + (bitIndex >> 3), bitIndex & 7, dataLength);
1.279 + OutputCharLineMultiplied(printPos, scanLineBuffer, dataLength, 1, aClipRect);
1.280 + bitIndex += dataLength;
1.281 + printPos.iY++;
1.282 + }
1.283 + }
1.284 + else
1.285 + {
1.286 + CopyCharLine(scanLineBuffer, scanLineWords, aGlyphImage + (bitIndex >> 3), bitIndex & 7, dataLength);
1.287 + OutputCharLineMultiplied(printPos, scanLineBuffer, dataLength, repeatCount, aClipRect);
1.288 + printPos.iY += repeatCount;
1.289 + bitIndex += dataLength;
1.290 + }
1.291 + }
1.292 + }
1.293 +
1.294 +
1.295 +/**
1.296 +
1.297 +*/
1.298 +void CSwDirectGdiEngine::CopyCharLine(TUint32* aBinaryDataPtr, TInt aBufferWords, const TUint8* aData, TInt aBitShift, TInt aCharWidth)
1.299 + {
1.300 + aBitShift &= 7;
1.301 + TInt wordsToCopy = (aCharWidth + 31) >> 5;
1.302 + if (wordsToCopy > aBufferWords)
1.303 + {
1.304 + wordsToCopy = aBufferWords;
1.305 + }
1.306 + TUint32* ptrLimit = aBinaryDataPtr + wordsToCopy;
1.307 + TUint32* dataWord = (TUint32*)(TInt(aData) & ~3);
1.308 + aBitShift += (TInt(aData) - TInt(dataWord)) << 3;
1.309 + while (aBinaryDataPtr < ptrLimit)
1.310 + {
1.311 + *aBinaryDataPtr = *dataWord++;
1.312 + *aBinaryDataPtr >>= aBitShift;
1.313 + if (aBitShift)
1.314 + {
1.315 + *aBinaryDataPtr |= (*dataWord << (32 - aBitShift));
1.316 + }
1.317 + aBinaryDataPtr++;
1.318 + }
1.319 + }
1.320 +
1.321 +
1.322 +/**
1.323 +
1.324 +*/
1.325 +void CSwDirectGdiEngine::OutputCharLineMultiplied(TPoint aPrintPos, TUint32* aBuffer, TInt aDataLength, TInt aNum, const TRect& aClipRect)
1.326 + {
1.327 + if (aDataLength <= 0)
1.328 + {
1.329 + return;
1.330 + }
1.331 + TInt bufferWords = (aDataLength + 31) >> 5;
1.332 + TUint32* bufferLimit = aBuffer + bufferWords;
1.333 + if (aPrintPos.iX < aClipRect.iTl.iX)
1.334 + {
1.335 + TInt pixelExcess = aClipRect.iTl.iX - aPrintPos.iX;
1.336 + while (pixelExcess >= 32)
1.337 + {
1.338 + aBuffer++;
1.339 + bufferWords--;
1.340 + aDataLength -= 32;
1.341 + pixelExcess -= 32;
1.342 + }
1.343 + if (aDataLength <= 0)
1.344 + {
1.345 + return;
1.346 + }
1.347 + if (pixelExcess > 0)
1.348 + {
1.349 + TInt shiftUp = 32 - pixelExcess;
1.350 + TUint32* bufferPtr = aBuffer;
1.351 + while (bufferPtr < bufferLimit)
1.352 + {
1.353 + *bufferPtr >>= pixelExcess;
1.354 + if (bufferPtr < bufferLimit - 1)
1.355 + {
1.356 + *bufferPtr |= (*(bufferPtr + 1) << shiftUp);
1.357 + }
1.358 + bufferPtr++;
1.359 + }
1.360 + aDataLength -= pixelExcess;
1.361 + if (aDataLength <= 0)
1.362 + {
1.363 + return;
1.364 + }
1.365 + }
1.366 + aPrintPos.iX = aClipRect.iTl.iX;
1.367 + }
1.368 + if (aPrintPos.iX + aDataLength > aClipRect.iBr.iX)
1.369 + {
1.370 + TInt pixelExcess = aPrintPos.iX + aDataLength - aClipRect.iBr.iX;
1.371 + aDataLength -= pixelExcess;
1.372 + if (aDataLength <= 0)
1.373 + {
1.374 + return;
1.375 + }
1.376 + }
1.377 + while (aNum > 0)
1.378 + {
1.379 + if ((aPrintPos.iY >= aClipRect.iTl.iY) && (aPrintPos.iY < aClipRect.iBr.iY))
1.380 + {
1.381 + iDrawDevice->WriteBinaryLine(aPrintPos.iX, aPrintPos.iY, aBuffer, aDataLength, iPenColor, GcDrawMode(iDrawMode));
1.382 + }
1.383 + aPrintPos.iY++;
1.384 + aNum--;
1.385 + }
1.386 + }
1.387 +
1.388 +
1.389 +/**
1.390 +Draw a rotated bitmap glyph.
1.391 +
1.392 +@param aPos Position to start drawing glyph after rotation has been applied.
1.393 +@param aGlyphImage Pointer to the glyph image data.
1.394 +@param aGlyphImageSize Glyph image size.
1.395 +@param aClipRect Clipping rect.
1.396 +@param aRotation Rotation specifying how the glyph will be drawn.
1.397 +*/
1.398 +void CSwDirectGdiEngine::DrawRotatedBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.399 + const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation)
1.400 + {
1.401 + TPoint printPos(aPos);
1.402 + TInt dataLength = aGlyphImageSize.iWidth;
1.403 + TInt dataHeight = aGlyphImageSize.iHeight;
1.404 + TInt bitIndex = 0;
1.405 + TInt16 repeatCount = 0;
1.406 + TInt direction = (aRotation == DirectGdi::EGraphicsRotation270) ? 1 : -1;
1.407 + TUint32* scanLineBuffer = iDrawDevice->ScanLineBuffer();
1.408 + TInt scanLineWords = (iDrawDevice->ScanLineBytes()) << 3;
1.409 + for (TInt glyphLine = 0; glyphLine < dataHeight; glyphLine += repeatCount) // for lines in the glyph bitmap...
1.410 + {
1.411 + repeatCount = Load16(aGlyphImage + (bitIndex >> 3));
1.412 + repeatCount >>= bitIndex & 7;
1.413 + TInt multiLineFlag = repeatCount & 1;
1.414 + repeatCount >>= 1;
1.415 + repeatCount &= 0xf;
1.416 + bitIndex += 5;
1.417 + TInt signedRepeatCount = repeatCount * direction;
1.418 + if (multiLineFlag)
1.419 + {
1.420 + for (TInt currentLine = 0; currentLine < repeatCount; currentLine++)
1.421 + {
1.422 + CopyCharLine(scanLineBuffer, scanLineWords, aGlyphImage + (bitIndex >> 3), bitIndex & 7, dataLength);
1.423 + OutputCharLineVertical(printPos, scanLineBuffer, dataLength, 1, direction, aClipRect);
1.424 + bitIndex += dataLength;
1.425 + printPos.iX += direction;
1.426 + }
1.427 + }
1.428 + else
1.429 + {
1.430 + CopyCharLine(scanLineBuffer,scanLineWords, aGlyphImage + (bitIndex >> 3), bitIndex & 7, dataLength);
1.431 + OutputCharLineVertical(printPos, scanLineBuffer, dataLength, repeatCount, direction, aClipRect);
1.432 + printPos.iX += signedRepeatCount;
1.433 + bitIndex += dataLength;
1.434 + }
1.435 + }
1.436 + }
1.437 +
1.438 +
1.439 +/**
1.440 +
1.441 +*/
1.442 +void CSwDirectGdiEngine::OutputCharLineVertical(TPoint aPrintPos, TUint32* aBuffer, TInt aDataLength,
1.443 + TInt aNum, TInt aDirection, const TRect& aClipRect)
1.444 + {
1.445 +// const DirectGdi::TGraphicsRotation rotation = aUp ? DirectGdi::EGraphicsRotation270 : DirectGdi::EGraphicsRotation90;
1.446 +// TInt direction = (aRotation == DirectGdi::EGraphicsRotation270) ? 1 : -1;
1.447 + if (aDataLength <= 0)
1.448 + {
1.449 + return;
1.450 + }
1.451 + TInt bufferWords = (aDataLength + 31) >> 5;
1.452 + TUint32* bufferLimit = aBuffer + bufferWords;
1.453 + if (aDirection == 1)
1.454 + {
1.455 + if (aPrintPos.iY >= aClipRect.iBr.iY)
1.456 + {
1.457 + TInt pixelExcess = aPrintPos.iY - aClipRect.iBr.iY + 1;
1.458 + while (pixelExcess >= 32)
1.459 + {
1.460 + aBuffer++;
1.461 + aDataLength -= 32;
1.462 + pixelExcess -= 32;
1.463 + }
1.464 + if (aDataLength <= 0)
1.465 + {
1.466 + return;
1.467 + }
1.468 + if (pixelExcess > 0)
1.469 + {
1.470 + TInt shiftUp = 32 - pixelExcess;
1.471 + TUint32* bufferPtr = aBuffer;
1.472 + while (bufferPtr < bufferLimit)
1.473 + {
1.474 + *bufferPtr >>= pixelExcess;
1.475 + if (bufferPtr < bufferLimit - 1)
1.476 + *bufferPtr |= (*(bufferPtr + 1) << shiftUp);
1.477 + bufferPtr++;
1.478 + }
1.479 + aDataLength -= pixelExcess;
1.480 + if (aDataLength <= 0)
1.481 + {
1.482 + return;
1.483 + }
1.484 + }
1.485 + aPrintPos.iY = aClipRect.iBr.iY - 1;
1.486 + }
1.487 + if ((aPrintPos.iY - aDataLength) < (aClipRect.iTl.iY - 1))
1.488 + {
1.489 + TInt pixelExcess = aClipRect.iTl.iY - 1 - aPrintPos.iY + aDataLength;
1.490 + aDataLength -= pixelExcess;
1.491 + if (aDataLength <= 0)
1.492 + {
1.493 + return;
1.494 + }
1.495 + }
1.496 + }
1.497 + else
1.498 + {
1.499 + if (aPrintPos.iY < aClipRect.iTl.iY)
1.500 + {
1.501 + TInt pixelExcess = aClipRect.iTl.iY - aPrintPos.iY;
1.502 + while (pixelExcess >= 32)
1.503 + {
1.504 + aBuffer++;
1.505 + aDataLength -= 32;
1.506 + pixelExcess -= 32;
1.507 + }
1.508 + if (aDataLength <= 0)
1.509 + {
1.510 + return;
1.511 + }
1.512 + if (pixelExcess > 0)
1.513 + {
1.514 + TInt shiftup = 32 - pixelExcess;
1.515 + TUint32* bufferptr = aBuffer;
1.516 + while (bufferptr < bufferLimit)
1.517 + {
1.518 + *bufferptr >>= pixelExcess;
1.519 + if (bufferptr < bufferLimit - 1)
1.520 + *bufferptr |= (*(bufferptr + 1) << shiftup);
1.521 + bufferptr++;
1.522 + }
1.523 + aDataLength -= pixelExcess;
1.524 + if (aDataLength <= 0)
1.525 + {
1.526 + return;
1.527 + }
1.528 + }
1.529 + aPrintPos.iY = aClipRect.iTl.iY;
1.530 + }
1.531 + if (aPrintPos.iY + aDataLength > aClipRect.iBr.iY)
1.532 + {
1.533 + TInt pixelExcess = aPrintPos.iY + aDataLength - aClipRect.iBr.iY;
1.534 + aDataLength -= pixelExcess;
1.535 + if (aDataLength <= 0)
1.536 + {
1.537 + return;
1.538 + }
1.539 + }
1.540 + }
1.541 + CGraphicsContext::TDrawMode drawMode = GcDrawMode(iDrawMode);
1.542 + while (aNum > 0)
1.543 + {
1.544 + if ((aPrintPos.iX >= aClipRect.iTl.iX) && (aPrintPos.iX < aClipRect.iBr.iX))
1.545 + iDrawDevice->WriteBinaryLineVertical(aPrintPos.iX, aPrintPos.iY, aBuffer, aDataLength, iPenColor, drawMode, (aDirection == 1));
1.546 + aPrintPos.iX += aDirection;
1.547 + aNum--;
1.548 + }
1.549 + }
1.550 +
1.551 +
1.552 +/**
1.553 +Draw an antialiased glyph.
1.554 +
1.555 +@param aPos Position to start drawing gyph.
1.556 +@param aGlyphImage Pointer to the glyph image data.
1.557 +@param aGlyphImageSize Glyph image size.
1.558 +@param aClipRect Clipping rect.
1.559 +*/
1.560 +void CSwDirectGdiEngine::DrawAntiAliasedGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.561 + const TSize& aGlyphImageSize, const TRect& aClipRect)
1.562 + {
1.563 + const TInt topRow = Max(0, aClipRect.iTl.iY - aPos.iY);
1.564 + const TInt bottomRow = Min(aGlyphImageSize.iHeight, aClipRect.iBr.iY - aPos.iY);
1.565 + const TInt leftCol = Max(0, aClipRect.iTl.iX - aPos.iX);
1.566 + const TInt rightCol = Min(aGlyphImageSize.iWidth, aClipRect.iBr.iX - aPos.iX);
1.567 + const TUint8* p = aGlyphImage + (topRow * aGlyphImageSize.iWidth) + leftCol;
1.568 + const TInt x = aPos.iX + leftCol;
1.569 + TInt y = aPos.iY + topRow;
1.570 + const TInt cols = rightCol - leftCol;
1.571 +
1.572 + for (TInt row = topRow; row < bottomRow; row++, p += aGlyphImageSize.iWidth, y++)
1.573 + {
1.574 + iDrawDevice->WriteRgbAlphaMulti(x, y, cols, iPenColor, p);
1.575 + }
1.576 + }
1.577 +
1.578 +
1.579 +/**
1.580 +Draw a rotated antialiased glyph.
1.581 +
1.582 +@param aPos Position to start drawing gyph after rotation has been applied.
1.583 +@param aGlyphImage Pointer to the glyph image data.
1.584 +@param aGlyphImageSize Glyph image size.
1.585 +@param aClipRect Clipping rect.
1.586 +@param aRotation Rotation specifying how the glyph will be drawn.
1.587 +*/
1.588 +void CSwDirectGdiEngine::DrawRotatedAntiAliasedGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.589 + const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation)
1.590 + {
1.591 + const int KBufferSize = 32;
1.592 + TUint8 maskBuffer[KBufferSize];
1.593 + int topRow = 0;
1.594 + int bottomRow = 0;
1.595 + int leftCol = 0;
1.596 + int rightCol = 0;
1.597 + const TUint32 penColor = iPenColor.Internal();
1.598 + const TUint32 brushColor = iBrushColor.Internal();
1.599 +
1.600 + if (aRotation == DirectGdi::EGraphicsRotation270)
1.601 + {
1.602 + topRow = Max(0, aClipRect.iTl.iX - aPos.iX);
1.603 + bottomRow = Min(aGlyphImageSize.iHeight, aClipRect.iBr.iX - aPos.iX);
1.604 + leftCol = Max(0, aPos.iY - aClipRect.iBr.iY + 1);
1.605 + rightCol = Min(aGlyphImageSize.iWidth, aPos.iY - aClipRect.iTl.iY + 1);
1.606 + TInt y = aPos.iY - (rightCol - 1);
1.607 + for (TInt col = rightCol - 1; col >= leftCol; col--, y++)
1.608 + {
1.609 + TInt x = aPos.iX + topRow;
1.610 + for (TInt row = topRow; row < bottomRow; row += KBufferSize, x += KBufferSize)
1.611 + {
1.612 + TInt length = KBufferSize;
1.613 + if (length > bottomRow - row)
1.614 + {
1.615 + length = bottomRow - row;
1.616 + }
1.617 + const TUint8* p = aGlyphImage + row * aGlyphImageSize.iWidth + col;
1.618 + for (TInt i = 0; i < length; i++, p += aGlyphImageSize.iWidth)
1.619 + {
1.620 + maskBuffer[i] = *p;
1.621 + }
1.622 + iDrawDevice->WriteRgbAlphaMulti(x, y, length, iPenColor, maskBuffer);
1.623 + }
1.624 + }
1.625 + }
1.626 + else
1.627 + {
1.628 + topRow = Max(0, aPos.iX - aClipRect.iBr.iX + 1);
1.629 + bottomRow = Min(aGlyphImageSize.iHeight, aPos.iX - aClipRect.iTl.iX + 1);
1.630 + leftCol = Max(0, aClipRect.iTl.iY - aPos.iY);
1.631 + rightCol = Min(aGlyphImageSize.iWidth, aClipRect.iBr.iY - aPos.iY);
1.632 + int y = aPos.iY + leftCol;
1.633 + for (TInt col = leftCol; col < rightCol; col++, y++)
1.634 + {
1.635 + TInt x = aPos.iX - (bottomRow - 1);
1.636 + for (TInt row = bottomRow; row > topRow; row -= KBufferSize, x += KBufferSize)
1.637 + {
1.638 + int length = KBufferSize;
1.639 + if (length > row - topRow)
1.640 + length = row - topRow;
1.641 + const TUint8* p = aGlyphImage + (row - 1) * aGlyphImageSize.iWidth + col;
1.642 + for (TInt i = 0; i < length; i++, p -= aGlyphImageSize.iWidth)
1.643 + {
1.644 + maskBuffer[i] = *p;
1.645 + }
1.646 + iDrawDevice->WriteRgbAlphaMulti(x, y, length, iPenColor, maskBuffer);
1.647 + }
1.648 + }
1.649 + }
1.650 + }
1.651 +
1.652 +
1.653 +/**
1.654 +Draw a four colour glyph.
1.655 +
1.656 +@param aPos Position to start drawing gyph.
1.657 +@param aGlyphImage Pointer to the glyph image data.
1.658 +@param aGlyphImageSize Glyph image size.
1.659 +@param aClipRect Clipping rect.
1.660 +*/
1.661 +void CSwDirectGdiEngine::DrawFourColourGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.662 + const TSize& aGlyphImageSize, const TRect& aClipRect)
1.663 + {
1.664 + const TInt topRow = Max(0, aClipRect.iTl.iY - aPos.iY);
1.665 + const TInt bottomRow = Min(aGlyphImageSize.iHeight, aClipRect.iBr.iY - aPos.iY);
1.666 + const TInt leftCol = Max(0, aClipRect.iTl.iX - aPos.iX);
1.667 + const TInt rightCol = Min(aGlyphImageSize.iWidth, aClipRect.iBr.iX - aPos.iX);
1.668 + const TUint8* p = aGlyphImage + (topRow * aGlyphImageSize.iWidth) + leftCol;
1.669 + const TInt x = aPos.iX + leftCol;
1.670 + TInt y = aPos.iY + topRow;
1.671 + const TInt cols = rightCol - leftCol;
1.672 + const TUint32 penColor = iPenColor.Internal();
1.673 + const TUint32 shadowColor = iTextShadowColor.Internal();
1.674 + const TUint32 brushColor = iBrushColor.Internal();
1.675 +
1.676 + MOutlineAndShadowBlend* outlineAndShadow = NULL;
1.677 + const TInt err = iDrawDevice->GetInterface(KOutlineAndShadowInterfaceID, reinterpret_cast <TAny*&> (outlineAndShadow));
1.678 + if (err == KErrNone)
1.679 + {
1.680 + //There is a support for the interface with KOutlineAndShadowInterface id.
1.681 + for (TInt row = topRow; row < bottomRow; row++, p += aGlyphImageSize.iWidth, y++)
1.682 + {
1.683 + outlineAndShadow->WriteRgbOutlineAndShadow(x, y, cols, penColor, shadowColor, brushColor, p);
1.684 + }
1.685 + }
1.686 + else
1.687 + {
1.688 + // Assert if MOutlineAndShadowBlend interface is not implemented
1.689 + GRAPHICS_ASSERT_DEBUG(outlineAndShadow, EDirectGdiPanicInvalidInterfaceHandle);
1.690 + }
1.691 + }
1.692 +
1.693 +
1.694 +/**
1.695 +Draw a rotated four colour glyph.
1.696 +
1.697 +@param aPos Position to start drawing gyph after rotation has been applied.
1.698 +@param aGlyphImage Pointer to the glyph image data.
1.699 +@param aGlyphImageSize Glyph image size.
1.700 +@param aClipRect Clipping rect.
1.701 +@param aRotation Rotation specifying how the glyph will be drawn.
1.702 +*/
1.703 +void CSwDirectGdiEngine::DrawRotatedFourColourGlyph(const TPoint& aPos, const TUint8* aGlyphImage, const TSize& aGlyphImageSize,
1.704 + const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation)
1.705 + {
1.706 + const int KBufferSize = 32;
1.707 + TUint8 maskBuffer[KBufferSize];
1.708 + int topRow = 0;
1.709 + int bottomRow = 0;
1.710 + int leftCol = 0;
1.711 + int rightCol = 0;
1.712 + const TUint32 penColor = iPenColor.Internal();
1.713 + const TUint32 shadowColor = iTextShadowColor.Internal();
1.714 + const TUint32 brushColor = iBrushColor.Internal();
1.715 +
1.716 + MOutlineAndShadowBlend* outlineAndShadow = NULL;
1.717 + TInt err = iDrawDevice->GetInterface(KOutlineAndShadowInterfaceID, reinterpret_cast <TAny*&> (outlineAndShadow));
1.718 + if(err != KErrNone)
1.719 + {
1.720 + // Assert if MOutlineAndShadowBlend interface is not implemented
1.721 + GRAPHICS_ASSERT_DEBUG(outlineAndShadow, EDirectGdiPanicInvalidInterfaceHandle);
1.722 + }
1.723 +
1.724 + if (aRotation == DirectGdi::EGraphicsRotation270)
1.725 + {
1.726 + topRow = Max(0, aClipRect.iTl.iX - aPos.iX);
1.727 + bottomRow = Min(aGlyphImageSize.iHeight, aClipRect.iBr.iX - aPos.iX);
1.728 + leftCol = Max(0, aPos.iY - aClipRect.iBr.iY + 1);
1.729 + rightCol = Min(aGlyphImageSize.iWidth, aPos.iY - aClipRect.iTl.iY + 1);
1.730 + TInt y = aPos.iY - (rightCol - 1);
1.731 + for (TInt col = rightCol - 1; col >= leftCol; col--, y++)
1.732 + {
1.733 + TInt x = aPos.iX + topRow;
1.734 + for (TInt row = topRow; row < bottomRow; row += KBufferSize, x += KBufferSize)
1.735 + {
1.736 + TInt length = KBufferSize;
1.737 + if (length > bottomRow - row)
1.738 + {
1.739 + length = bottomRow - row;
1.740 + }
1.741 + const TUint8* p = aGlyphImage + row * aGlyphImageSize.iWidth + col;
1.742 + for (TInt i = 0; i < length; i++, p += aGlyphImageSize.iWidth)
1.743 + {
1.744 + maskBuffer[i] = *p;
1.745 + }
1.746 + //There is a support for the interface with KOutlineAndShadowInterface id.
1.747 + outlineAndShadow->WriteRgbOutlineAndShadow(x, y, length, penColor, shadowColor, brushColor, maskBuffer);
1.748 + }
1.749 + }
1.750 + }
1.751 + else
1.752 + {
1.753 + topRow = Max(0, aPos.iX - aClipRect.iBr.iX + 1);
1.754 + bottomRow = Min(aGlyphImageSize.iHeight, aPos.iX - aClipRect.iTl.iX + 1);
1.755 + leftCol = Max(0, aClipRect.iTl.iY - aPos.iY);
1.756 + rightCol = Min(aGlyphImageSize.iWidth, aClipRect.iBr.iY - aPos.iY);
1.757 + int y = aPos.iY + leftCol;
1.758 + for (TInt col = leftCol; col < rightCol; col++, y++)
1.759 + {
1.760 + TInt x = aPos.iX - (bottomRow - 1);
1.761 + for (TInt row = bottomRow; row > topRow; row -= KBufferSize, x += KBufferSize)
1.762 + {
1.763 + int length = KBufferSize;
1.764 + if (length > row - topRow)
1.765 + length = row - topRow;
1.766 + const TUint8* p = aGlyphImage + (row - 1) * aGlyphImageSize.iWidth + col;
1.767 + for (TInt i = 0; i < length; i++, p -= aGlyphImageSize.iWidth)
1.768 + {
1.769 + maskBuffer[i] = *p;
1.770 + }
1.771 + //There is a support for the interface with KOutlineAndShadowInterface id.
1.772 + outlineAndShadow->WriteRgbOutlineAndShadow(x, y, length, penColor, shadowColor, brushColor, maskBuffer);
1.773 + }
1.774 + }
1.775 + }
1.776 + }
1.777 +
1.778 +
1.779 +/**
1.780 +Helper function to clip the array to the clip rect.
1.781 +
1.782 +@param aArray Start of array of data to be clipped.
1.783 +@param aArrayLimit End of array of data to be clipped.
1.784 +@param aDataWd Length of data.
1.785 +@param aDataHt Height of data.
1.786 +@param aPos Position to start drawing from.
1.787 +@param aClipRect Rectangle to clip data array to.
1.788 +
1.789 +@return Pointer to array of clipped data.
1.790 +*/
1.791 +TUint32* CSwDirectGdiEngine::ClipBinaryArray(TUint32* aArray, TUint32* aArrayLimit, TInt& aDataWd, TInt& aDataHt, TPoint& aPos, const TRect& aClipRect)
1.792 + {
1.793 + TUint32* arrayPtr = aArray;
1.794 + TInt clipDiff = aClipRect.iTl.iX - aPos.iX;
1.795 + if (clipDiff > 0)
1.796 + {
1.797 + while (arrayPtr < aArrayLimit)
1.798 + {
1.799 + *arrayPtr++ >>= clipDiff;
1.800 + }
1.801 + aDataWd -= clipDiff;
1.802 + aPos.iX = aClipRect.iTl.iX;
1.803 + arrayPtr = aArray;
1.804 + }
1.805 + if ((aPos.iX + aDataWd > aClipRect.iBr.iX) && (aDataWd > 0))
1.806 + {
1.807 + aDataWd = aClipRect.iBr.iX - aPos.iX;
1.808 + }
1.809 + clipDiff = aClipRect.iTl.iY - aPos.iY;
1.810 + if (clipDiff > 0)
1.811 + {
1.812 + aDataHt -= clipDiff;
1.813 + arrayPtr += clipDiff;
1.814 + aPos.iY = aClipRect.iTl.iY;
1.815 + }
1.816 + if (((aPos.iY + aDataHt) > (aClipRect.iBr.iY)) && (aDataHt > 0))
1.817 + {
1.818 + aDataHt = aClipRect.iBr.iY - aPos.iY;
1.819 + }
1.820 + return arrayPtr;
1.821 + }