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

📄 rtwin.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}		//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);		    XUnlockDisplay(pDisplay);		}		//Do strike-through 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->isStruckOut())		{		    INT32 thickness =			    (yLowerRightScaled - yScaled) / 18;		    if(thickness < 1)		    {			thickness = 1;		    }		    XLockDisplay(pDisplay);		    XSetForeground(pDisplay, gc, xcolor.pixel);		    XSetBackground(pDisplay, gc, 0);		    //XXXEH-Is this needed?:		    XFillRectangle(pDisplay, pixmap, gc,			    xScaled,			    yScaled + ((yLowerRightScaled - yScaled) / 2),			    lScaledLowerRightXWithOffsets-xScaled + 				   (ULONG32) fXScaleFactor,			    thickness);		    XUnlockDisplay(pDisplay);		}	    }	    char* textbuffer=pContainer->getBuffer();	    char buf[3]; /* Flawfinder: ignore */  //[0] holds char to be drawn (or [0] and				// [1] do if DBCS), and [1] (or [2] if 				// 2-byte char) holds '\0';	    buf[1] = buf[2] = '\0';	    INT16 bufLen = 0;	    if (textbuffer && pContainer->getTextLengthPlus1() < 1)	    {		continue; // while (pos)            }		    ULONG32 ulCharset = pContainer->getFontCharset();	    LONG32 cx = xScaled;	    LONG32 cy = yScaled + fs->ascent - 2;	    XLockDisplay(pDisplay);	    XSetForeground(pDisplay, gc, xcolor.pixel);	    XUnlockDisplay(pDisplay);	    // draw each character @ offset in x from the first:	    do	    {		char ch = *textbuffer;		UINT16 usCh = ch;		buf[0] = ch;		bufLen = 1;		if (IS_MULTI_BYTE_CHARSET(ulCharset))		{		    if (IS_UNICODE_CHARSET(ulCharset) ||			(UCHAR)ch >= DBCS_MIN_LEAD_BYTE_VAL)		    {		       // ch is lead byte of a 2-byte char.			textbuffer++;			ch = *textbuffer;			bufLen = 2; //is a 2-byte char.			buf[1] = ch; //==trail byte.			usCh <<= 8; //move lead byte into high byte.			usCh |= ch; //put trail byte into low byte.		    }		}		//XXXEH- test this DBCS stuff^^!!!		ULONG32 ulLookupCharWidth = GET_CHAR_WIDTH(pContainer, usCh);		if(bWindowWidthIsNotTheOriginalValue)		{		    ulLookupCharWidth =			    LONG32(((float)ulLookupCharWidth *			    (float)lWindowWidth) /			    (float)pTextWindow->getWidth());		}		//First, horizontally center the character inside		// its bounding box in case its native width is		// noticably different from its cross-platform-		// table-assigned width:		LONG32 lXPlatWidth = (LONG32)ulLookupCharWidth;		LONG32 lNativeWidth = (bufLen>1?			//use fixed x-plat width for double byte chars:			lXPlatWidth:			(LONG32)XTextWidth(  fs, buf, 1) );		LONG32 lCrossPlatVsNativeWidthOffset = 0L;		if(lNativeWidth  &&  //Should never be 0, but...			lXPlatWidth!=lNativeWidth) 		{		    //Note: we should not adjust lNativeWidth by any		    // scale factor even if bWindowWidthIsNotTheOriginalValue		    // because that's already been accounted for in the font		    // point size.		    //Note: this can be negative!:		    lCrossPlatVsNativeWidthOffset =			    (lXPlatWidth-lNativeWidth)/2;		}		XDrawString(pDisplay, pixmap, gc,			cx + lCrossPlatVsNativeWidthOffset,			cy,			buf, bufLen);		cx += ulLookupCharWidth;	    } while(*(++textbuffer));	    pContainer->textHasChangedSinceLastDraw(FALSE);	    //Since OnTimeSync()/OnTimeSynch() may not yet have been	    //called, we need to time-bounds check:	} // if (pContainer->textHasChangedSinceLastDraw())    } // while(pos)    if (bFreeColors)    {	UINT32 colors[1];	colors[0] = xcolor.pixel;    }    XLockDisplay(pDisplay);    XFreeGC(pDisplay, gc);    XUnlockDisplay(pDisplay);    // now blt this information to the screen    IHXVideoSurface* pVideoSurface = (IHXVideoSurface*)pEvent->param1;        HX_ASSERT(NULL != pVideoSurface);    if(NULL == pVideoSurface)    {	return FALSE; //no draw.    }    pVideoSurface->AddRef();    //avoid race condition when re-allocating offscreen bitmap:    // TODO: if (!pTextWindow->m_bHandlingWindowResizing)	LONG32 w, h;	w = pTextWindow->getWindowWidth(); 	h = pTextWindow->getWindowHeight();	XLockDisplay(pDisplay);	XImage *pImage = XGetImage(pDisplay, pixmap,		0, 0, w, h,		AllPlanes,		ZPixmap);	XUnlockDisplay(pDisplay);	CHXxRect destRect, srcRect;	destRect.SetRect(0, 0, w, h);	srcRect.SetRect(0, 0, w, h);        pEvent->result = pVideoSurface->Blt(		    (UCHAR *)pImage->data,		    pBitmapInfoHeader,		    destRect, 		    srcRect);        XDestroyImage(pImage);	    HX_RELEASE(pVideoSurface);	    return TRUE;}/////////////////////////////////////////////////////////////////////////////// Function://  BOOL//  PaintBackground//  (//  	TextWindow* pTextWindow,//      Display*    pDisplay,//      Colormap    cmap,//      Pixmap      pixmap//  )//// Purpose://  This function paints the background of the window//static voidPaintBackground(TextWindow* pTextWindow, Display* pDisplay, Colormap cmap, Pixmap pixmap){    XColor bgColor;    convertCOLORTYPEtoXVisualFormat(pTextWindow->getBackgroundColor(),				    bgColor);    // get color    HXFindBestXColor(pDisplay, cmap, &bgColor);    XGCValues gcv;    gcv.background = 0;    gcv.foreground = bgColor.pixel;    XLockDisplay(pDisplay);    GC gc = XCreateGC(pDisplay, pixmap, GCForeground | GCBackground, &gcv);    XFillRectangle(pDisplay, pixmap, gc,		   0, 0,		   // Note: this used to use getWidth and getHeight		   pTextWindow->getWindowWidth(),		   pTextWindow->getWindowHeight());    XUnlockDisplay(pDisplay);    UINT32 colors[1];    colors[0] = bgColor.pixel;    // TODO: save and reuse this GC?    XLockDisplay(pDisplay);    XFreeGC(pDisplay, gc);    XUnlockDisplay(pDisplay);    return;}// TODO KPW: this code really should use the resource database// to allow users to specify a particular fontSpec for // each facestatic struct { const char *face; const char *family; } fontMap[] = {    { "[default]", "times" }, // default if no map found, must be first    { "times", "times" },    { "courier", "courier" },    { "courier new", "courier" },    { "arial", "helvetica" },    { "arial black", "helvetica" },    { "arial narrow", "helvetica" },    { "arial rounded MT bold", "helvetica" },    { "helvetica", "helvetica" },    { NULL, NULL }};/*  XXXEH: all recognized font names in RT should be added    to the above struct once the appropriate "backup" font face has been    determined. */static const char*MapFaceToFamily(const char *face){   register int i;   for (i = 0; NULL != face   &&  fontMap[i].face != NULL; i++)   {       if (strcasecmp(face, fontMap[i].face) == 0)       {	   return(fontMap[i].family);       }   }   // return the default   return(fontMap[0].family);}// Note: this may return NULLstatic XFontStruct*GetFontStruct(Display *pDisplay, TextWindow* pTextWindow,	      TextContainer* pContainer,	      float fYScaleFactor){    if (!pTextWindow)    {	return NULL;    }    Dict* pDict = pTextWindow->m_font_dict;    char fontSpec[1024]; /* Flawfinder: ignore */    const char* pFontFamily = NULL;    const char* pAlternateFontFamily = NULL;    XFontStruct* fs = NULL;    pFontFamily = pContainer->getFontFaceString(	    pTextWindow->getMajorContentVersion(),	    pTextWindow->getMinorContentVersion());    pAlternateFontFamily = MapFaceToFamily(	    pContainer->getFontFaceString(	    pTextWindow->getMajorContentVersion(),	    pTextWindow->getMinorContentVersion()));    ULONG32 ulCharset = pContainer->getFontCharset();    //XXXEH: this is a half-*ssed attempt to support CJK fonts.  This will    // do at least as good a job as prior code (that rendered all CJK chars    // using Latin-1 characters, i.e, it was unreadable):    if (IS_MULTI_BYTE_CHARSET(ulCharset))    {	sprintf(fontSpec, "-*-%s-%s-%s-*--%ld-*-75-75-*-*-*-%s", /* Flawfinder: ignore */		//ignore face name in this build; just load any available		// font in this charset		"fixed",		pContainer->isBold() ? "bold" : "medium",		pContainer->isItalicized() ? "i" : "r",		(INT32)(pContainer->getFontPointSize() * fYScaleFactor),		(ulCharset & HX_JAPANESE_CHARSET?"jisx0208.1990-0":			(ulCharset & HX_KOREAN_CHARSET?// /XXXEH- for plain text, we need to use this only if user specified// "ksc5601" or "hangeul" charset, but not "johab"; need to find out what to// use for "johab":				"KSC5601.1987-0": 				(HX_CHINESE_CHARSET?				//XXXEH: CNSxxx is Taiwan charset but most				// likely doesn't map exactly to big5; need				// more research to find big5 charset:					(ulCharset==CHARSET__big5?// /XXXEH- Doh!!: I think these are backwards; we need to fix this, however,// only for plain text and (maybe) for new RealText version:					 "GB2312.1980-0":"CNS11643.1986-1"):					"*" /*:load whatever if not CJK.*/				)			)		) );    }    else    {	sprintf(fontSpec, "-*-%s-%s-%s-*--%ld-*-75-75-*-*-*-*", /* Flawfinder: ignore */		pFontFamily,		pContainer->isBold() ? "bold" : "medium",		pContainer->isItalicized() ? "i" : "r",		(INT32)(pContainer->getFontPointSize() * fYScaleFactor));    }    Dict_entry* ent = pDict->find(fontSpec);    if (ent)    {	fs = (XFontStruct*)ent->obj;    }    else    {	XLockDisplay(pDisplay);	fs = XLoadQueryFont(pDisplay, fontSpec);	XUnlockDisplay(pDisplay);	if (fs)	{	    pDict->enter(fontSpec, fs);	}	else if(!IS_MULTI_BYTE_CHARSET(ulCharset))	{	    // /Helps minimize effect of PR 33172:	    // We want to put the originally-requested font spec	    // into the dictionary with the XFontStruct of the *alternate*	    // one so that, next time we try to load the same font spec,	    // we end up getting the alternate one out of the dict.	    // (The true fix for PR 33172 is to delete the entries in the	    // dict prior to deleting the dict);	    char szAlternateFontSpec[1024]; /* Flawfinder: ignore */	    sprintf(szAlternateFontSpec, "-*-%s-%s-%s-*--%ld-*-75-75-*-*-*-*", /* Flawfinder: ignore */		    pAlternateFontFamily,		    pContainer->isBold() ? "bold" : "medium",		    pContainer->isItalicized() ? "i" : "r",		    (INT32)(pContainer->getFontPointSize() * fYScaleFactor));	    XLockDisplay(pDisplay);	    fs = XLoadQueryFont(pDisplay, szAlternateFontSpec);	    XUnlockDisplay(pDisplay);	    if (fs)	    {		pDict->enter(fontSpec, fs);	    }	}    }    // if it's not in the dict and we couldn't load it substitute either    // "times". "helvetica", or "courier", depending on the font face's    // RT-defined "spacing" similarities to one of those font faces.    // XXXEH: note: if a CJK (DBCS) charset is specified and the load query    // font failed for the given point size, that doesn't mean it would    // for sure fail at other point sizes, so we need to special case those    // and maintain the charsets when for-looping through the point size    // queries:    int ulFontPointSize = pContainer->getFontPointSize() -1;    INT32 lScaledHeight = (INT32)((float)ulFontPointSize * fYScaleFactor);    while (!fs && lScaledHeight >= 8 )    {	ULONG32 ulFontFaceIndex = pContainer->getFontFace();          sprintf(fontSpec, "-*-%s-%s-%s-*--%ld-*-75-75-*-*-*-*", /* Flawfinder: ignore */		(ulFontFaceIndex&USES_COURIER_SPACING?"courier":		    (ulFontFaceIndex&USES_ARIAL_SPACING?"helvetica":			"times")),		"medium", "r",  lScaledHeight);	 Dict_entry* ent = pDict->find(fontSpec);	 if (ent)	 {	     fs = (XFontStruct*)ent->obj;	 }	 else	 {	     XLockDisplay(pDisplay);	     fs = XLoadQueryFont(pDisplay, fontSpec);	     XUnlockDisplay(pDisplay);	     if (fs)	       pDict->enter(fontSpec, fs);	 }	 lScaledHeight--;    }    return fs;}#endif /* _BEOS */

⌨️ 快捷键说明

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