⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawptxt.cpp

📁 linux下的一款播放器
💻 CPP
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: drawptxt.cpp,v 1.1.2.1 2004/07/09 01:50:38 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** *////////////////////////////////////////////////////////////////////////////////// drawptxt.cpp	////	(Macintosh version of ../WIN/drawptxt.cpp)////#include "hxtypes.h"#include "hxassert.h"#include "hxslist.h"#include "hxstack.h"#include "chxxtype.h"#include "rt_types.h"#include "txtattrb.h"#include "txtcntnr.h"#include "textline.h"#include "txtwindw.h"#include "textprsr.h"#include "rtwin.h"#include "atocolor.h"#include "fontdefs.h"#include "fontinfo.h"#ifndef _MAC_MACHO#include "ugworld.h"#include "udstate.h"#endif#include "hxcom.h"#include "hxvsurf.h" // for IHXVideoSurface#include "hxevent.h" // for HX_SURFACE_UPDATE#ifndef _MAC_MACHO#include <Quickdraw.h>#endif#ifndef _MAC_MACHO#include "udutils.h" // to get topLeft and botRight macros#endif#include "platform/mac/maclibrary.h" // for DWORD#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE		static char HX_THIS_FILE[] = __FILE__;#endif// /These are in mrtwin.cpp:UINT16	Convert8BitTo16Bit(UINT8 x);void ConvertCOLORTYPEtoRGBColor(RGBColor& rgbColor, COLORTYPE colorVal);BOOLDrawPlainText(TextWindow* pTextWindow, void* pvoidEvent,	void* pPaintstruct, ULONG32 ulTimeOfCurrentDraw){    HX_ASSERT_VALID_PTR(pTextWindow);    if(!pTextWindow)    {	return FALSE;    }        BOOL b_FunctionSucceeded = TRUE;    LONG32 lWindowWidth = pTextWindow->getWindowWidth();    LONG32 lWindowHeight = pTextWindow->getWindowHeight();    HXxEvent* pEvent = (HXxEvent*)pvoidEvent;    HX_ASSERT(pEvent);	        ULONG32 listSize = pTextWindow->textCntnrListSize();    Rect updateRect;    ::SetRect(&updateRect, 0, 0, pTextWindow->getWindowWidth(), pTextWindow->getWindowHeight());     // /XXXEH- use the following if and when the core starts doing    // subrects on the Mac:    CHXxRect* pDestRect = pEvent?            (CHXxRect*)((HXxEvent*)pvoidEvent)->param2 :            NULL;    COLORTYPE backColorType = pTextWindow->getBackgroundColor();    UINT32 ulEffectiveFgOpacity = pTextWindow->getMediaOpacity();    UINT32 ulEffectiveBgOpacity = pTextWindow->getBackgroundOpacity();    UINT32 ulChromaKey = pTextWindow->getChromaKey();    UINT32 ulChromaKeyTolerance = pTextWindow->getChromaKeyTolerance();    UINT32 ulChromaKeyOpacity = pTextWindow->getChromaKeyOpacity();            // /Helps fix PR 67215:    // Initialize chromaKey flag. If the background color is the same as the    // chroma key, then we know we are applying the chroma key. Also, when we    // draw text of a certain color later down in this method, we may be    // setting this flag, depending on the text color:    BOOL bChromaKeyWasApplied = FALSE;    if (pTextWindow->isChromaKeySet())    {        if (DoesChromaKeyMatch(backColorType, ulChromaKey,		ulChromaKeyTolerance))        {            if (ulChromaKeyOpacity < 255)            {                bChromaKeyWasApplied = TRUE;                ulEffectiveBgOpacity = ulChromaKeyOpacity;            }        }    }        // /Draw all the text:    {	GWorldPtr theMacGWorld;	CGrafPtr theSavePort;	GDHandle theSaveDevice;	Rect theBounds = updateRect;	{	    ::GetGWorld(&theSavePort, &theSaveDevice);	    RGBColor theForeColor, theBackColor;	    ::GetForeColor(&theForeColor);	    ::GetBackColor(&theBackColor);	    RgnHandle theClipRgn = ::NewRgn();	    ::GetClip(theClipRgn);	    theMacGWorld = NULL;	    	    Rect gwRect = theBounds;	                Point topLeft;            Point botRight;                        topLeft.h = gwRect.left;            topLeft.v = gwRect.top;                        botRight.h = gwRect.right;            botRight.v = gwRect.bottom;            	    LocalToGlobal(&topLeft);	    LocalToGlobal(&botRight);                        gwRect.left = topLeft.h;            gwRect.top = topLeft.v;            gwRect.right = botRight.h;            gwRect.bottom = botRight.v;	    	    	    theMacGWorld = pTextWindow->m_pOffScreenWorld;	    if (theMacGWorld)	    {		::SetGWorld(theMacGWorld, NULL);		::SetOrigin(theBounds.left, theBounds.top);		::SetClip(theClipRgn);		::LockPixels((::GetGWorldPixMap(theMacGWorld)));		::RGBForeColor(&theForeColor);		::RGBBackColor(&theBackColor);	    }	    else	    {		b_FunctionSucceeded = FALSE;		goto cleanup;	    }	    ::DisposeRgn(theClipRgn);	}	RGBColor backColor, prevBackColor;	ConvertCOLORTYPEtoRGBColor(backColor, backColorType);	::GetBackColor(&prevBackColor);	// /Paint the background with the specified color:	// /Just paint using OS API with non-alpha color:	::RGBBackColor(&backColor);	::EraseRect(&updateRect);	//Only draw the text again if we really need to:	if (listSize  &&		(TIME_INVALID != ulTimeOfCurrentDraw) )	{	    LISTPOSITION pos = pTextWindow->GetStartPosition();	    while(pos)	    {		TextContainer* curTextContainerPtr =				/*  Note: effectively does GetAt(pos++):  */				(TextContainer*)pTextWindow->GetNext(pos);		if (curTextContainerPtr->textHasChangedSinceLastDraw()  ||			curTextContainerPtr->textShouldBeDrawn())		{		    _CHAR* pTextbuffer = curTextContainerPtr->getBuffer();		    ULONG32 ulTextLengthPlusOneOfCurTC =			    curTextContainerPtr->getTextLengthPlus1();		    if (!pTextbuffer  ||  ulTextLengthPlusOneOfCurTC <= 1)		    {		        curTextContainerPtr->textHasChangedSinceLastDraw(FALSE);		        continue;		    }		    LONG32 lUpperLeftXWithOffsets =			    curTextContainerPtr->getXUpperLeftCorner();		    LONG32 lLowerRightXWithOffsets =			    curTextContainerPtr->getXLowerRightCorner();		    LONG32 lUpperLeftYWithOffsets =			    curTextContainerPtr->getYUpperLeftCorner();		    LONG32 lLowerRightYWithOffsets =			    curTextContainerPtr->getYLowerRightCorner();		    LONG32 xScaled = lUpperLeftXWithOffsets;		    LONG32 yScaled = lUpperLeftYWithOffsets;		    		    const char* pCurFontFaceString = // /NOTE: NULL is a valid value:			    pTextWindow->getDefaultFontFaceString();			    		    const char* pCharset = pTextWindow->getDefaultCharsetString();		    		    ULONG32 ulCharset = CHARSET__default;		    if (pCharset) // /If NULL, just use user's default		    {			pTextWindow->getCharsetULONG32(pCharset,				PLAINTEXT_MAX_CHARSET_LEVEL_SUPPORTED, ulCharset);						BOOL bMightNeedCharsetTranslationForMac = FALSE;						if (CHARSET__iso_8859_1 == ulCharset)			{			    bMightNeedCharsetTranslationForMac = TRUE;			}						// /XXXEH- handle other charset conversions here.						if (bMightNeedCharsetTranslationForMac)			{			    if (!pTextWindow->isCharsetTranslatedForOS())			    {				// /This may change some of the buffer contents;				// if so, it's on a 1-byte-for-1-byte basis:				if (ConvertAcrossCharacterSets(pTextbuffer,					ulCharset, TRUE,					PLAINTEXT_MAX_CHARSET_LEVEL_SUPPORTED))				{				    pTextWindow->setCharsetTranslatedForOS(TRUE);				}			    }			}		    }		    		    Style tcStyle = NULL;#if XXXEH_HANDLE_UNDERLINE		    BOOL bIsUnderlined =			    pTextWindow->isUnderlinedPlainText();#else		    BOOL bIsUnderlined = FALSE;#endif		    ULONG32 ulFontWeight = pTextWindow->getDefaultFontWeight();		    // /XXXEH- add bold-threshold defined value:		    if (ulFontWeight > DEFAULT_FONT_WEIGHT + 100)		    {			tcStyle += bold;		    }		    if (pTextWindow->isDefaultFontStyleItalic())		    {			tcStyle += italic;		    }		    ULONG32 ulBasePointSize = pTextWindow->getDefaultPtSize();		    		    TextFace(tcStyle);		    BOOL bFontFaceFoundOnSystem = FALSE;		    INT16 iFaceIndx = 0;		    		    if (pCurFontFaceString)		    {			INT16 iLenOfCurFontFace = strlen(pCurFontFaceString)+1;			char* pFontFaceBuf = new char[iLenOfCurFontFace];			if (!pFontFaceBuf)			{			     b_FunctionSucceeded = FALSE;			     goto cleanup;			}			*pFontFaceBuf = '\0';			//change C str to Pascal str			c2pstrcpy((StringPtr)pFontFaceBuf, pCurFontFaceString);			GetFNum((StringPtr)pFontFaceBuf, (short*)&iFaceIndx);			bFontFaceFoundOnSystem = (iFaceIndx!=0);			delete [] pFontFaceBuf;		    }		    //else it's an empty string so do mapping, below...		    // /If the author specified an explicit font and it was		    // not found installed on the system, use a reasonable		    // substitute font based on the charset:		    if (!bFontFaceFoundOnSystem  &&  pCurFontFaceString  &&			    pCharset != NULL)		    {			if (CHARSET__x_sjis == ulCharset)			{			    GetFNum("\pOsaka", (short*)&iFaceIndx);			    // /XXXEH- if that failed, look for other			    // well-known Japanese shift-jis fonts:			}			else if (CHARSET__gb2312 == ulCharset)			{			    // /Simplified Chinese:			    GetFNum("\p'宋体", (short*)&iFaceIndx);			}			else if (CHARSET__big5 == ulCharset  ||				CHARSET__x_euc_tw == ulCharset)			{			    // /Traditional Chinese:			    GetFNum("\p灿

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -