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

📄 hxparse.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 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 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (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.  
 *  
 * 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 ***** */ 

#include "hlxclib/stdlib.h"
//#include "hlxclib/stdio.h"
#include "hlxclib/ctype.h"

#include "hxtypes.h"
#include "hxresult.h"
#include "hxcom.h"
#include "chxxtype.h"
#include "hxwintyp.h"
#include "hxstring.h"
#include "hxstrutl.h"
#include "hxparse.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif


/*
 * our smil/html color string table
 */


static const struct smilColorTable
{
    const char* m_pColorName;
    UINT8 m_ucRed;
    UINT8 m_ucGreen;
    UINT8 m_ucBlue;
} SmilColorTable[] =
{
    {"black", 	0x00, 0x00, 0x00},
    {"silver", 	0xc0, 0xc0, 0xc0},
    {"gray",  	0x80, 0x80, 0x80},
    {"white", 	0xff, 0xff, 0xff},
    {"maroon",	0x80, 0x00, 0x00},
    {"red",   	0xff, 0x00, 0x00},
    {"purple",	0x80, 0x00, 0x80},
    {"fuchsia", 0xff, 0x00, 0xff},
    {"green",	0x00, 0x80, 0x00},
    {"lime",	0x00, 0xff, 0x00},
    {"olive",	0x80, 0x80, 0x00},
    {"yellow",	0xff, 0xff, 0x00},
    {"navy",	0x00, 0x00, 0x80},
    {"blue",	0x00, 0x00, 0xff},
    {"teal",	0x00, 0x80, 0x80},
    {"aqua",	0x00, 0xff, 0xff},
    {0,		0x00, 0x00, 0x00}
};


/****************************************************************************
 *  getColorElement
 *
 *  parses a hex value from the string passed in.
 */

UINT8
getColorElement(const char* pColorFrag, int len)
{
    UINT8 ucValue = 0;

    char* pTmpBuf = new char[len+1];
    strncpy(pTmpBuf, pColorFrag, len); /* Flawfinder: ignore */
    pTmpBuf[len] = 0;

    ucValue = (UINT8)strtol(pTmpBuf, 0, 16);
    delete[] pTmpBuf;
    return ucValue;
}


/****************************************************************************
 *  HXParseColor
 *
 *  Parses a smil/html color string and returns its HXxColor value.  The
 *  string should be in one of the following formats: "#RGB", "#RRGGBB",
 *  or one of the pre-defined strings in the table at the top of this file.
 */

HX_RESULT
HXParseColor(const char* pColorString, REF(HXxColor) theColor)
{
    HX_RESULT theErr = HXR_INVALID_PARAMETER;
    theColor = 0;
    UINT8 ucRed = 0;
    UINT8 ucGreen = 0;
    UINT8 ucBlue = 0;
    if(pColorString[0] == '#')
    {
	if(strlen(pColorString) == 4)
	{
	    /* #rgb, duplicate the numbers */
	    char tmpBuf[6]; /* Flawfinder: ignore */
	    tmpBuf[0] = tmpBuf[1] = pColorString[1];
	    tmpBuf[2] = tmpBuf[3] = pColorString[2];
	    tmpBuf[4] = tmpBuf[5] = pColorString[3];
	    ucRed = getColorElement(&tmpBuf[0], 2);
	    ucGreen = getColorElement(&tmpBuf[2], 2);
	    ucBlue = getColorElement(&tmpBuf[4], 2);
	    theErr = HXR_OK;
	}
	else if(strlen(pColorString) == 7)
	{
	    /* #rrggbb */
	    ucRed = getColorElement(&pColorString[1], 2);
	    ucGreen = getColorElement(&pColorString[3], 2);
	    ucBlue = getColorElement(&pColorString[5], 2);
	    theErr = HXR_OK;
	}
    }
    else if (!strncmp(pColorString, "rgb(", 4))
    {
        // This color is in the form rgb(0,128,255) or
        // in the form rgb(0%,50%,100%)
        //
        // Make a copy of the string, since strtok
        // is destructive
        char* pCopy = new char [strlen(pColorString) + 1];
        if (pCopy)
        {
            strcpy(pCopy, pColorString); /* Flawfinder: ignore */
            // Get past the "rgb("
            UINT32 ulTmp = 0;
            char*  pStr  = strtok(pCopy, "(,)");
            // Get the red string
            pStr = strtok(NULL, "(,)");
            if (pStr)
            {
                // Use HXParseOpacity to parse the red component
                theErr = HXParseOpacity((const char*) pStr, ulTmp);
                if (SUCCEEDED(theErr))
                {
                    // Assign the red component
                    ucRed = (BYTE) ulTmp;
                    // Get the green string
                    pStr = strtok(NULL, "(,)");
                    if (pStr)
                    {
                        // Use HXParseOpacity to parse the green component
                        theErr = HXParseOpacity((const char*) pStr, ulTmp);
                        if (SUCCEEDED(theErr))
                        {
                            // Assign the green component
                            ucGreen = (BYTE) ulTmp;
                            // Get the blue string
                            pStr = strtok(NULL, "(,)");
                            if (pStr)
                            {
                                // Use HXParseOpacity to parse the blue component
                                theErr = HXParseOpacity((const char*) pStr, ulTmp);
                                if (SUCCEEDED(theErr))
                                {
                                    // Assign the blue string
                                    ucBlue = (BYTE) ulTmp;
                                }
                            }
                            else
                            {
                                theErr = HXR_INVALID_PARAMETER;
                            }
                        }
                    }
                    else
                    {
                        theErr = HXR_INVALID_PARAMETER;
                    }
                }
            }
        }
        HX_VECTOR_DELETE(pCopy);
    }
    else
    {
	// string, try to get it from the color table
	int i = 0;
	const char* pColorName = SmilColorTable[i].m_pColorName;
	while(pColorName)
	{
	    if(strcmp(pColorName, pColorString) == 0)
	    {
		ucRed = SmilColorTable[i].m_ucRed;
		ucBlue = SmilColorTable[i].m_ucBlue;
		ucGreen = SmilColorTable[i].m_ucGreen;
		theErr = HXR_OK;
		break;
	    }
	    pColorName = SmilColorTable[++i].m_pColorName;
	}
    }

    // Check and see if it's a system color definition.
    // See http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
    // for more info about these.
#ifdef _WINDOWS
    if (FAILED(theErr))
    {
        BOOL  bMatch = FALSE;
        INT32 lIndex = 0;
        if (!strcasecmp(pColorString, "ActiveBorder"))
        {
            lIndex = COLOR_ACTIVEBORDER;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "ActiveCaption"))
        {
            lIndex = COLOR_ACTIVECAPTION;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "AppWorkspace"))
        {
            lIndex = COLOR_APPWORKSPACE;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "Background"))
        {
            lIndex = COLOR_BACKGROUND;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "ButtonFace"))
        {
            lIndex = COLOR_BTNFACE;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "ButtonHighlight"))
        {
            lIndex = COLOR_BTNHILIGHT;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "ButtonShadow"))
        {
            lIndex = COLOR_BTNSHADOW;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "ButtonText"))
        {
            lIndex = COLOR_BTNTEXT;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "CaptionText"))
        {
            lIndex = COLOR_CAPTIONTEXT;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "GrayText"))
        {
            lIndex = COLOR_GRAYTEXT;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "Highlight"))
        {
            lIndex = COLOR_HIGHLIGHT;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "HighlightText"))
        {
            lIndex = COLOR_HIGHLIGHTTEXT;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "InactiveBorder"))
        {
            lIndex = COLOR_INACTIVEBORDER;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "InactiveCaption"))
        {
            lIndex = COLOR_INACTIVECAPTION;
            bMatch = TRUE;
        }
        else if (!strcasecmp(pColorString, "InactiveCaptionText"))
        {

⌨️ 快捷键说明

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