graphicsdeviceinterface/gdi/sgdi/FONT.CPP
changeset 36 01a6848ebfd7
parent 0 5d03bc08d59c
child 45 36b2e23a8629
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 #include "GDIPANIC.h"
    22 #include "GDIPANIC.h"
    23 #include "glyphsample.h"
    23 #include "glyphsample.h"
    24 #include "gdiinline.inl"
    24 #include "gdiinline.inl"
    25 #include "gdistructs.h"
    25 #include "gdistructs.h"
    26 #include "gdiconsts.h"
    26 #include "gdiconsts.h"
       
    27 #include "gdiplatapi.h"
    27 
    28 
    28 /**
    29 /**
    29  Names holds the types & data associated with the glyph selection
    30  Names holds the types & data associated with the glyph selection
    30  algorithm in CFont::GetCharacterPosition().
    31  algorithm in CFont::GetCharacterPosition().
    31 @internalComponent
    32 @internalComponent
   343 /** Constructs a TFontSpec object with the specified typeface and height. 
   344 /** Constructs a TFontSpec object with the specified typeface and height. 
   344 
   345 
   345 The object's font style is set to the default: EPostureUpright, EStrokeWeightNormal, 
   346 The object's font style is set to the default: EPostureUpright, EStrokeWeightNormal, 
   346 and EPrintPosNormal.
   347 and EPrintPosNormal.
   347 
   348 
   348 @param aTypefaceName The name of the typeface (e.g. "Roman"). 
   349 @param aTypefaceName The name of the typeface (e.g. "Roman"). It should be no
   349 @param aHeight The height of the typeface, in twips. */
   350 	longer than KMaxTypefaceNameLength characters in length.
   350 	{
   351 @param aHeight The height of the typeface, in twips. 
   351 	iTypeface.iName=aTypefaceName;
   352 @panic GDI 6, if aTypefaceName is more than KMaxTypefaceNameLength characters long.
       
   353 */
       
   354 	{
       
   355 	iTypeface.SetName(aTypefaceName);
   352 	}
   356 	}
   353 
   357 
   354 
   358 
   355 EXPORT_C TBool TFontSpec::operator==(const TFontSpec& aFontSpec) const
   359 EXPORT_C TBool TFontSpec::operator==(const TFontSpec& aFontSpec) const
   356 /** Compares this font specification with another.
   360 /** Compares this font specification with another.
   601 @internalTechnology
   605 @internalTechnology
   602 */
   606 */
   603 EXPORT_C TInt TTypeface::ScriptTypeForMetrics() const
   607 EXPORT_C TInt TTypeface::ScriptTypeForMetrics() const
   604 	{
   608 	{
   605 	return (KTTypefaceMaskScript & iFlags) >> KTTypefaceBitsNumAttrib;
   609 	return (KTTypefaceMaskScript & iFlags) >> KTTypefaceBitsNumAttrib;
       
   610 	}
       
   611 
       
   612 /**
       
   613 Sets the name of the typeface. This method should be used rather than
       
   614 directly accessing the iName public member.
       
   615 @param aName The name of the typeface (e.g. "Roman"). It should be no 
       
   616 	longer than KMaxTypefaceNameLength characters in length.
       
   617 @panic GDI 6, if aName is more than KMaxTypefaceNameLength characters
       
   618 	long.
       
   619 */
       
   620 EXPORT_C void TTypeface::SetName(const TDesC& aName)
       
   621 	{
       
   622 	GDI_ASSERT_ALWAYS(aName.Length() <= KMaxTypefaceNameLength, EGdiPanic_TypefaceNameOverflow);
       
   623 	iName=aName;
       
   624 	}
       
   625 
       
   626 /**
       
   627 Returns the name of the typeface.
       
   628 @return The name of the typeface.
       
   629 */
       
   630 EXPORT_C const TDesC& TTypeface::Name() const
       
   631 	{
       
   632 	return iName;
   606 	}
   633 	}
   607 
   634 
   608 
   635 
   609 //
   636 //
   610 // CFont
   637 // CFont
  1587 		}
  1614 		}
  1588 	// -3 to offset EScriptDefault, EScriptNone and EScriptOther
  1615 	// -3 to offset EScriptDefault, EScriptNone and EScriptOther
  1589 	// being the first three elements in TScript.
  1616 	// being the first three elements in TScript.
  1590 	return TPtrC(KTScript2GlyphSample[aScript - 3]);
  1617 	return TPtrC(KTScript2GlyphSample[aScript - 3]);
  1591 	}
  1618 	}
       
  1619 
       
  1620 
       
  1621 EXPORT_C RFontTable::RFontTable():iTableContent(0), iLength(0),
       
  1622         iFont(NULL), iTag(0)
       
  1623     {
       
  1624     // a null constructor.
       
  1625     }
       
  1626 
       
  1627 EXPORT_C TInt
       
  1628 RFontTable::Open(CFont& aFont, TUint32 aTag) 
       
  1629     {
       
  1630     TGetFontTableParam param;
       
  1631     param.iTag = aTag;
       
  1632     
       
  1633     // remember the parameters, to be used when releasing the font table.
       
  1634     iFont = &aFont;
       
  1635     iTag = aTag;
       
  1636     
       
  1637     TInt ret = aFont.ExtendedFunction(KFontGetFontTable, (TAny *)&param);
       
  1638     if (KErrNone == ret)
       
  1639         {
       
  1640         iTableContent = (TAny *)param.iContent;
       
  1641         iLength = param.iLength;
       
  1642         }
       
  1643     return ret;
       
  1644     }
       
  1645 
       
  1646 EXPORT_C TInt 
       
  1647 RFontTable::TableLength() const
       
  1648     {
       
  1649     return iLength;
       
  1650     }
       
  1651 
       
  1652 EXPORT_C const TUint8*
       
  1653 RFontTable::TableContent() const 
       
  1654     {
       
  1655     return (TUint8*)iTableContent;
       
  1656     }
       
  1657 
       
  1658 EXPORT_C void
       
  1659 RFontTable::Close()
       
  1660     {
       
  1661     if (NULL != iFont)
       
  1662         {
       
  1663         (void)iFont->ExtendedFunction(KFontReleaseFontTable, (TAny *)&iTag);
       
  1664         }
       
  1665     iTableContent = 0;
       
  1666     iLength = 0;
       
  1667     iFont = NULL;
       
  1668     iTag = 0;
       
  1669     }
       
  1670 
       
  1671 EXPORT_C 
       
  1672 RGlyphOutlineIterator::RGlyphOutlineIterator():iOutlines(0), iLengths(0), 
       
  1673     iCursor(-1), iCount(0), iFont(NULL), iCodes(NULL), iHinted(EFalse)
       
  1674     {
       
  1675     // a null constructor.
       
  1676     }
       
  1677 
       
  1678 EXPORT_C TInt
       
  1679 RGlyphOutlineIterator::Open(CFont& aFont, TUint* aCodes, TInt aCount, TBool aHinted) 
       
  1680     {
       
  1681     if (NULL == aCodes || 0 == aCount)
       
  1682         {
       
  1683         return KErrArgument;
       
  1684         }
       
  1685     TGetGlyphOutlineParam param;
       
  1686     iLengths = (TInt *)User::Alloc(sizeof(TInt) * aCount);
       
  1687     if (NULL == iLengths) 
       
  1688         {
       
  1689         return KErrNoMemory;
       
  1690         }
       
  1691     iOutlines = (TAny **)User::Alloc(sizeof(TAny *) * aCount);
       
  1692     if (NULL == iOutlines)
       
  1693         {
       
  1694         User::Free(iLengths);
       
  1695         iLengths = NULL;
       
  1696         return KErrNoMemory;
       
  1697         }
       
  1698     
       
  1699     param.iLengths = iLengths; 
       
  1700     param.iCount = aCount;
       
  1701     param.iCodes = aCodes; 
       
  1702     param.iHinted = aHinted;
       
  1703     param.iOutlines = iOutlines; 
       
  1704         
       
  1705     /* information needed in Close() */
       
  1706     iCodes = (TUint *)User::Alloc(sizeof(TUint) * aCount);
       
  1707     if (NULL == iCodes) 
       
  1708         {
       
  1709         User::Free(iLengths);
       
  1710         User::Free(iOutlines);
       
  1711         iLengths = NULL;
       
  1712         iOutlines = NULL;
       
  1713         return KErrNoMemory;
       
  1714         }
       
  1715     Mem::Copy(iCodes, aCodes, aCount*sizeof(TUint));
       
  1716     iFont = &aFont;
       
  1717     iHinted = aHinted;
       
  1718     iCount = aCount;
       
  1719     
       
  1720     TInt ret = aFont.ExtendedFunction(KFontGetGlyphOutline, (TAny *)&param);
       
  1721     if (KErrNone != ret)
       
  1722         {
       
  1723         User::Free(iLengths);
       
  1724         User::Free(iOutlines);
       
  1725         User::Free(iCodes);
       
  1726         iLengths = NULL;
       
  1727         iOutlines = NULL;
       
  1728         iCodes = NULL;
       
  1729         iFont = NULL;
       
  1730         }
       
  1731     else 
       
  1732         {
       
  1733         iCursor = 0;
       
  1734         }
       
  1735 
       
  1736     return ret;
       
  1737     }
       
  1738 
       
  1739 EXPORT_C const TUint8*
       
  1740 RGlyphOutlineIterator::Outline() const
       
  1741     {
       
  1742     GDI_ASSERT_ALWAYS(iCursor >= 0, EGdiPanic_Unknown);
       
  1743     
       
  1744     if (iLengths[iCursor] < 0) 
       
  1745         {
       
  1746         return NULL;
       
  1747         }
       
  1748     else 
       
  1749         {
       
  1750         return (const TUint8*)iOutlines[iCursor];
       
  1751         }
       
  1752     }
       
  1753 
       
  1754 EXPORT_C TInt 
       
  1755 RGlyphOutlineIterator::OutlineLength() const 
       
  1756     {
       
  1757     GDI_ASSERT_ALWAYS(iCursor >= 0, EGdiPanic_Unknown);
       
  1758     
       
  1759     if (iLengths[iCursor] < 0) 
       
  1760         {
       
  1761         return KErrGeneral;
       
  1762         }
       
  1763     else 
       
  1764         {
       
  1765         return iLengths[iCursor];
       
  1766         }
       
  1767     }
       
  1768 
       
  1769 EXPORT_C TInt
       
  1770 RGlyphOutlineIterator::Next()
       
  1771     {
       
  1772     if (iCursor >= 0 && iCursor < iCount-1) 
       
  1773         {
       
  1774         ++iCursor;
       
  1775         return KErrNone;
       
  1776         }
       
  1777     else
       
  1778         {
       
  1779         iCursor = -1; 
       
  1780         // if the iterator goes beyond the last element [when
       
  1781         // Next() returns KErrNotFound], the next call
       
  1782         // to Outline() or OutlineLength() will panic.
       
  1783         
       
  1784         return KErrNotFound;
       
  1785         }
       
  1786     }
       
  1787 
       
  1788 EXPORT_C void
       
  1789 RGlyphOutlineIterator::Close()
       
  1790     {
       
  1791     TReleaseGlyphOutlineParam param;
       
  1792     param.iCount = iCount;
       
  1793     param.iHinted = iHinted;
       
  1794     param.iCodes = iCodes;
       
  1795     
       
  1796     if (NULL != iFont)
       
  1797         {
       
  1798         iFont->ExtendedFunction(KFontReleaseGlyphOutline, (TAny *)&param);
       
  1799         }
       
  1800     
       
  1801     iFont = NULL;
       
  1802     iCount = 0;
       
  1803     User::Free(iLengths);
       
  1804     iLengths = NULL;
       
  1805     iCursor = -1;
       
  1806     User::Free(iCodes);
       
  1807     iCodes = NULL;
       
  1808     User::Free(iOutlines);
       
  1809     iOutlines = NULL;
       
  1810     }