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

📄 drawptxt.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: drawptxt.cpp,v 1.1.2.4 2004/07/09 13:08:06 pankajgupta 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//// Function://  BOOL DrawPlainText(TextWindow* pTextWindow, void* pvEvent, void* pvPixmap,//	    ULONG32 ulTimeOfCurrentDraw);// Purpose://  This function handles the rendering of plain text by calling an//  OS-specific API to draw the text in the given window.  Note that, since//  this funciton deals strictly with plain text, it doesn't need to worry//  about doing anything to any particular piece of text, e.g., underlining,//  coloring, font sizing, ...etc., but it *does* have to do that for *all*//  text if a <param> in the SMIL file that uses this text has dictated such//  an attribute value (for the entire text).//// Returns://  Returns FALSE on error, TRUE otherwise. //#if (!defined(_BEOS))#include <X11/Intrinsic.h>#include <X11/StringDefs.h>#endif#include "hxtypes.h"#include "hxassert.h"#include "hxstack.h"#include "hxslist.h"#include "rt_types.h"#include "fontdefs.h"#include "fontinfo.h"#include "txtattrb.h"#include "txtcntnr.h"#include "textline.h"#include "atocolor.h"#include "atotime.h" //for live time comparison: IsTimeAMoreRecentThanTimeB()#include "chxxtype.h"                                                           #include "txtwindw.h" //for class TextWindow.                                   #include "hxcom.h"                                                              #include "hxvsurf.h"                                                           #include "dict.h"#include "hxcom.h"#include "unixcmap.h"#include "../../rtwin.h"#include "drawptxt.h"#if (!defined(_BEOS))#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE		static char HX_THIS_FILE[] = __FILE__;#endif// /These are all in ./rtwin.cpp:void convertCOLORTYPEtoXVisualFormat(COLORTYPE RGBVal, XColor& xcolor);static XFontStruct* GetFontStruct(Display*, TextWindow*, TextContainer*, float);static void PaintBackground(TextWindow*, Display*, Colormap, Pixmap);/////////////////////////////////////////////////////////////////////////////// Function://  BOOL//  DrawPlainText(TextWindow* pTextWindow, void* pvEvent,//	void* pvPixmap, ULONG32 ulTimeOfCurrentDraw)//// Purpose://  This function does the actual rendering of plan text//// Returns://  Returns FALSE on error, TRUE otherwise. //BOOLDrawPlainText(TextWindow* pTextWindow, void* pvEvent, void* pvPixmap,	ULONG32 ulTimeOfCurrentDraw){    HX_ASSERT_VALID_PTR(pTextWindow);    HX_ASSERT(pvEvent);    HX_ASSERT_VALID_PTR(pvPixmap);    if(!pTextWindow  ||  !pvEvent  ||  !pvPixmap)    {	return FALSE;    }    LONG32 lWindowWidth = pTextWindow->getWindowWidth();    LONG32 lWindowHeight = pTextWindow->getWindowHeight();    HXxEvent *pEvent = (HXxEvent*)pvEvent;        // retrieve the X11 object we'll need to do the drawing    Pixmap pixmap = *((Pixmap*)pvPixmap);    HXxWindow *pWindow = (HXxWindow*)pEvent->param2;    Display* pDisplay = (Display*)(pWindow->display);    Colormap cmap = HXGetXColormap(pDisplay, (Window)pWindow->window);    // fill in the background    PaintBackground(pTextWindow, pDisplay, cmap, pixmap);    if (ulTimeOfCurrentDraw == TIME_INVALID)    {	return TRUE;    }    if (pTextWindow->textCntnrListSize() < 1)    {	return TRUE;    }        // This is freed at end of proc, so code should avoid    // using return below here    XLockDisplay(pDisplay);    GC gc = XCreateGC(pDisplay, pixmap, 0, NULL);    XUnlockDisplay(pDisplay);    // TODO: check return value of XCreateGC    XColor xcolor;    BOOL bFreeColors = FALSE;    float fXScaleFactor = (float)lWindowWidth / (float)pTextWindow->getWidth();    float fYScaleFactor = (float)lWindowHeight / (float)pTextWindow->getHeight();    // Iterate over each TextContainer in the window    LISTPOSITION pos = pTextWindow->GetStartPosition();    while (pos)    {	TextContainer* pContainer = NULL;	XFontStruct* fs = NULL;	COLORTYPE textColor;	//  Note: GetNext(pos) effectively does GetAt(pos++)	pContainer = (TextContainer*)pTextWindow->GetNext(pos);	if (pContainer->textHasChangedSinceLastDraw()  ||		pContainer->textShouldBeDrawn())	{	    //Check to make sure pContainer's text is located	    // in the window before we go to the trouble of	    // drawing it	    LONG32 lUpperLeftXWithOffsets =		    pContainer->getXUpperLeftCorner();	    LONG32 lLowerRightXWithOffsets =		    pContainer->getXLowerRightCorner();	    LONG32 lUpperLeftYWithOffsets =		    pContainer->getYUpperLeftCorner();	    LONG32 lLowerRightYWithOffsets =		    pContainer->getYLowerRightCorner();	    LONG32 xScaled = lUpperLeftXWithOffsets;	    LONG32 yScaled = lUpperLeftYWithOffsets;	    LONG32 lScaledUpperLeftXWithOffsets =		    lUpperLeftXWithOffsets;	    LONG32 lScaledLowerRightXWithOffsets =		    lLowerRightXWithOffsets;	    LONG32 lScaledUpperLeftYWithOffsets =		    lUpperLeftYWithOffsets;	    LONG32 lScaledLowerRightYWithOffsets =		    lLowerRightYWithOffsets;	    ///Make sure pContainer's text is located in the	    ///window before we go to the trouble of doing a TextOut:	    if(	   (lScaledUpperLeftXWithOffsets > pTextWindow->getWindowWidth()) 		    ||  (lScaledLowerRightXWithOffsets < 0)		    ||  (lScaledUpperLeftYWithOffsets > pTextWindow->getWindowHeight()) 		    ||  (lScaledLowerRightYWithOffsets < 0) )	    {		continue; //text doesn't overlap the window.	    }	    // check the time	    //First, if we're live, we need to compare times keeping	    // ULONG32-wrap-around in mind:	    BOOL bBeginTimeIsMoreRecentThanCurTime =		    IsTimeAMoreRecentThanTimeB(		    pContainer->getBeginTime(),		    ulTimeOfCurrentDraw,		    pTextWindow->isLiveSource());	    BOOL bCurTimeIsMoreRecentThanEndTime =		    IsTimeAMoreRecentThanTimeB(		    ulTimeOfCurrentDraw,		    pContainer->getEndTime(),		    pTextWindow->isLiveSource());	    //Sanity check:	    if(TIME_INVALID == pContainer->getEndTime())	    {		HX_ASSERT(!bCurTimeIsMoreRecentThanEndTime);	    }	    if(bBeginTimeIsMoreRecentThanCurTime  ||		    bCurTimeIsMoreRecentThanEndTime)	    {		continue; // while (pos)	    }	    fs = GetFontStruct(pDisplay, pTextWindow,		     pContainer, fYScaleFactor);	    if (fs == NULL)	    {		// This means we couldn't find any font to render with.		// TODO: put some debugging messages here		continue; // while(pos)	    }	    XLockDisplay(pDisplay);	    XSetFont(pDisplay, gc, fs->fid);	    XUnlockDisplay(pDisplay);	    textColor = pContainer->getTextColor();	    if (pTextWindow->getType() == TYPE_TICKERTAPE)	    {	        textColor = pContainer->getTickertapeTextColor();	    }	    convertCOLORTYPEtoXVisualFormat(textColor, xcolor);	    bFreeColors = TRUE;	    // get color	    HXFindBestXColor(pDisplay, cmap, &xcolor);	    //if bgcolor is not transparent, and/or if isUnderlined	    // is TRUE, draw a rect (or line for underline) manually	    // behind the entire text rather than letting textout do	    // it for each letter (which is slower and sometimes leaves	    // gaps if the letter spacing is slightly different than	    // the os would natively space it:	    COLORTYPE textBgColor = pContainer->getTextBackgroundColor();	    if((BAD_RGB_COLOR != textBgColor  &&		    TRANSPARENT_COLOR != textBgColor)  ||		    pContainer->isUnderlined()  ||		    pContainer->isStruckOut())	    {		LONG32 yLowerRightScaled =			lScaledLowerRightYWithOffsets;		//XXXEH- TODO: make sure UNIX has the same problem:		//Fix for bug 6527; when double sized, we want to		// double the padding on the right edge.  This		// "padding" (which used to be +1 always) is		// necessary when drawing a rect in Windows (& UNIX?) because		// PaintRectangle draws up to, but not including,		// the right edge:		LONG32 additionalWidth = 1;		if(lLowerRightYWithOffsets != 0) //avoid div by 0.		{		    additionalWidth =			yLowerRightScaled /			lLowerRightYWithOffsets;		}		if(additionalWidth < 1)		{		    additionalWidth=1;		}		UINT32 bgColor = 0;		if(BAD_RGB_COLOR != textBgColor  &&			TRANSPARENT_COLOR != textBgColor)		{		    XColor bgColor;		    convertCOLORTYPEtoXVisualFormat(textBgColor,						    bgColor);		    // get color		    HXFindBestXColor(pDisplay, cmap, &bgColor);		    XLockDisplay(pDisplay);		    XSetForeground(pDisplay, gc, bgColor.pixel);		    XSetBackground(pDisplay, gc, 0);		    XFillRectangle(pDisplay, pixmap, gc,			    xScaled,			    yScaled,			    //In UNIX, width and height are used			    // unlike in Windows where absolute lower			    // right corner position is used, so we			    // have to subtract the upper left corner:			    (lScaledLowerRightXWithOffsets-xScaled) +				    additionalWidth,			    (yLowerRightScaled-yScaled)+1);		    XUnlockDisplay(pDisplay);		    UINT32 colors[1];		    colors[0] = bgColor.pixel;		}		//Do underlining manually now (due to		// possible gaps if alternate font has to be		// used and forced spacing is not quite as os		// calculates it):		if(pContainer->isUnderlined())		{		    INT32 thickness =			    (yLowerRightScaled - yScaled) / 12;		    if(thickness < 1)		    {			thickness = 1;		    }		    if(pContainer->isBold())		    {			thickness += (thickness/2);		    }		    XLockDisplay(pDisplay);		    XSetForeground(pDisplay, gc, xcolor.pixel);		    XSetBackground(pDisplay, gc, 0); 		    //XXXEH-Is this needed?:		    XFillRectangle(pDisplay, pixmap, gc,			    xScaled,			    yLowerRightScaled - thickness + 1,			    lScaledLowerRightXWithOffsets-xScaled + 				   (ULONG32) fXScaleFactor,			    thickness);

⌨️ 快捷键说明

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