Ejemplo n.º 1
0
//static unsigned short *contstr=NULL;
static int ft_Font_FontConvStr(char* pText, unsigned short **ppDst, int *pLenDst)
{
    int i;
    int len;
    if(!pText)
        return _FT_FONT_NO;

    *pLenDst = 0;
    len = strlen(pText);
    if(len > 0)
    {
        if (len > FT_FONT_STR_LEN)
        {
            len = FT_FONT_STR_LEN;
            M_TRACE(DEBUG_TRACE, FT_MODE, "too much string for conv len = %d\n", len);
        }

        for(i=0; i<FT_FONT_CONV_NUM; i++)
        {
            /* 自动转换字符格式 */
            if(_FT_FONT_SUCC == ft_Font_IconvCharSet(pText, len, ppDst, pLenDst, ftIconvCharSet[i]))
            {
                M_TRACE(DEBUG_TRACE, FT_MODE, "Success the Char Set %d\n", i);
                return _FT_FONT_SUCC;
            }
        }
    }

    return _FT_FONT_FAIL;
}
Ejemplo n.º 2
0
int FontConvTxtStr_2_Unicode(char* pText, unsigned short **ppDst, int *pLenDst)
{
    int i;
    int len;

    if(!pText)
    {
        M_TRACE(WARING_TRACE, FT_MODE, "ptxt is null\r\n");
        return _FT_FONT_NO;
    }

    len = strlen(pText);
    if(len > 0)
    {
        for(i = 0; i < FT_FONT_CONV_NUM; i++)
        {
            /* 自动转换字符格式 */
            if(_FT_FONT_SUCC == ft_Font_IconvCharSet(pText, len, ppDst, pLenDst, ftIconvCharSet[i]))
            {
                M_TRACE(DEBUG_TRACE, FT_MODE, "Success the Char Set %d\n", i);
                return _FT_FONT_SUCC;
            }
        }
    }

    M_TRACE(WARING_TRACE, FT_MODE, "input len is zero\r\n");
    return _FT_FONT_FAIL;
}
Ejemplo n.º 3
0
//开始一个文件的播放
//filename 文件名称,网络连接等等
//pRegion  现实的区域
int start_av_engine(char *filename, GrRegion *pRegion)
{
    int                 ret;
    int                 length;
    int                 pos = av_engine_parameter_pos;
    ipcMsgQueueData_t   msg;

    length = strlen(filename);
    if (length > av_engine_parameter_pos)
    {
        M_TRACE(WARING_TRACE, AV_MODE, "filename too long %d\r\n", length);
        return -1;
    }

    memset(msg.msg_data, 0, IPC_MSG_DATA_MAX_LENGTH);
    memcpy(msg.msg_data, filename, length);

    if (pRegion)
    {
        memcpy(msg.msg_data+pos+0,  &(pRegion->x), 4);
        memcpy(msg.msg_data+pos+4,  &(pRegion->y), 4);
        memcpy(msg.msg_data+pos+8,  &(pRegion->w), 4);
        memcpy(msg.msg_data+pos+12, &(pRegion->h), 4);
    }

    msg.msg_type = av_engine_start;

    ret = sendMsgQueue(AV_ENGINE_ID, &msg);
    if (ret < 0)
    {
        M_TRACE(WARING_TRACE, AV_MODE, "%d\r\n", ret);
    }

    return ret;
}
Ejemplo n.º 4
0
int init_udp_instance(udp_item_def *pHandle)
{
    struct sockaddr_in socketaddr;
    struct timeval timeout;

    //open a udp socket
    pHandle->socket_fp = socket(AF_INET, SOCK_DGRAM, 0);
    if (pHandle->socket_fp == -1)
    {
        M_TRACE(ERROR_TRACE, NET_MODE, "can not open the socket\r\n");
        return 0;
    }

    //set the timeout 1ms

    timeout.tv_sec = 0;
    timeout.tv_usec = 1000;
    setsockopt(pHandle->socket_fp,
               SOL_SOCKET, SO_SNDTIMEO,
               (const char*)&timeout,
               sizeof(timeout));

    timeout.tv_sec = 0;
    timeout.tv_usec = 1000;
    setsockopt(pHandle->socket_fp,
               SOL_SOCKET, SO_RCVTIMEO,
               (const char*)&timeout,
               sizeof(timeout));

    //bind the socket and set the local port and ip address;
    socketaddr.sin_family = AF_INET;
    socketaddr.sin_port = htons(pHandle->near_port);
    socketaddr.sin_addr.s_addr = INADDR_ANY;
    memset(&(socketaddr.sin_zero), 0, 8);
    if (bind(pHandle->socket_fp,
             (struct sockaddr *) &(socketaddr),
             sizeof(struct sockaddr)) == -1)
    {
        M_TRACE(ERROR_TRACE, NET_MODE, "can not bind the socket\r\n");
        return 0;
    }


    if (pHandle->multicast)
    {
        struct ip_mreq mreq;
        mreq.imr_multiaddr.s_addr = inet_addr(pHandle->remote_ip);
        mreq.imr_interface.s_addr = htonl(INADDR_ANY);
        if(setsockopt(pHandle->socket_fp, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0)
        {
            M_TRACE(ERROR_TRACE, NET_MODE, "can not add the multicast failed!\n");
            return -1;
        }
    }

    M_TRACE(DEBUG_TRACE, NET_MODE, "init udp instance success\r\n");
    return 1;
}
Ejemplo n.º 5
0
float read_temperature(void)
{
    int ret;

    unsigned int u32DeviceAddress = TEMPERATURE_I2C_ADDR;
    unsigned int u32I2cNum  = I2C_DEVICE_NUM;
    unsigned int u32RegAddr = 0;
    unsigned int u32RegAddrCount = 1;
    unsigned int u32ReadNumber = 2;
    unsigned char *pData = NULL;
    unsigned short sdata, stmperature;
    float temp;

    ret = init_i2c_module();
    if (ret <= 0)
    {
        M_TRACE(ERROR_TRACE, SYS_MODE, "open i2c module failure\n");
        return -256;
    }

    pData =(unsigned char *) &(sdata);
    ret = i2c_read(u32I2cNum, u32DeviceAddress,
               u32RegAddr, u32RegAddrCount,
               pData, u32ReadNumber);
    if (ret <= 0)
    {
        M_TRACE(DEBUG_TRACE, SYS_MODE, "read i2c failure\n");
        return -256;
    }

    close_i2c_module();

    stmperature = pData[0];
	stmperature = (stmperature<< 8) + pData[1];
	temp =  SHIFT(stmperature, 4) / 16 +
			SHIFT(stmperature, 5) / 8 +
			SHIFT(stmperature, 6) / 4 +
			SHIFT(stmperature, 7) / 2 +
			SHIFT(stmperature, 8) +
			SHIFT(stmperature, 9) * 2 +
			SHIFT(stmperature, 10) * 4 +
			SHIFT(stmperature, 11) * 8 +
			SHIFT(stmperature, 12) * 16 +
			SHIFT(stmperature, 13) * 32 +
			SHIFT(stmperature, 14) * 64;

	if (stmperature & 0x8000)
	{
        temp = -1.0 * temp;
	}

    //M_TRACE(DEBUG_TRACE, SYS_MODE, "%3.4f\n", temp);

    return temp;
}
Ejemplo n.º 6
0
int ft_Font_Conv_Unicode_Str(char* pSrc, int lenSrc, unsigned char *pDst, int LenDst)
{
    iconv_t 	varConv;
    size_t 	lenIn, lenOut;
    char    *pOut;
    int i;

    for(i=0; i<1; i++)
    {
        /* Open iconv Lib */
        varConv = iconv_open("GBK", ftIconvCharSet[i]);
        if(varConv == (iconv_t)(_FT_FONT_FAIL))
        {
            M_TRACE(ERROR_TRACE, FT_MODE, "Iconv Open %s Fail!\n", ftIconvCharSet[i]);
            //continue;
            return _FT_FONT_FAIL;
        }

        /* Convert String */
        lenOut = (lenSrc+1024) * sizeof(short);
        lenIn = lenSrc;
        pOut = (char *)pDst;

        while (lenIn > 0)
        {
            if((_FT_FONT_FAIL) == iconv(varConv, (char* *)(&pSrc), &lenIn,	&pOut, &lenOut))
            {
                M_TRACE(DEBUG_TRACE, FT_MODE, "Iconv ErrNo: %d!\n", errno);
                //iconv_close(varConv);
               // return _FT_FONT_FAIL;
                break;
            }
        }

        /* Convert '\0' */
        if((_FT_FONT_FAIL) == iconv(varConv, NULL, NULL, &pOut, &lenOut))
        {
            M_TRACE(DEBUG_TRACE, FT_MODE, "Iconv Str Fail!\n");
            iconv_close(varConv);
            return _FT_FONT_FAIL;
            //continue;
        }

        /* Set Size */
        iconv_close(varConv);
        if(lenOut > 0)
        {
            M_TRACE(DEBUG_TRACE, FT_MODE, "IConv str success\n");
            return _FT_FONT_SUCC;
        }
    }

    return _FT_FONT_FAIL;
}
Ejemplo n.º 7
0
int close_udp_instance(udp_item_def *pHandle)
{
    if (pHandle->socket_fp != -1)
    {
        close(pHandle->socket_fp);
        M_TRACE(DEBUG_TRACE, NET_MODE, "close udp socket\r\n");
        return 1;
    }

    M_TRACE(ERROR_TRACE, NET_MODE, "close udp socket failure\r\n");
    return 0;
}
Ejemplo n.º 8
0
//字符转化
static int ft_Font_FontConvStrBufRelease(unsigned short *pBuf)
{
    M_TRACE(DEBUG_TRACE, FT_MODE, "%x\n", pBuf);
    if (pBuf)
        free(pBuf);

    return 0;
}
Ejemplo n.º 9
0
int ft_Font_Init(void)
{
    int ret;

    if (bInit)
        return 0;

    configCharSet_ft_Font();

    ret = FT_Init_FreeType(&ft_Font_FTLibrary);
    if( ret )
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "FT_Init_FreeType: [%08x]\n", ret);
        return _FT_FONT_FAIL;
    }

    ret = FT_New_Face(ft_Font_FTLibrary, FT_FONT_FILE_PATH, 0, &ft_Font_FtFace);
    if( ret )
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "FT_New_Face: [%d]\n", ret);
        return _FT_FONT_FAIL;
    }

    ret = FT_Select_Charmap(ft_Font_FtFace, ft_encoding_unicode);
    if( ret )
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "FT_Select_Charmap: [%d]\n", ret);
        return _FT_FONT_FAIL;
    }

    bInit = 1;

    ft_MEM.cost_mem_width = 0;
    ft_MEM.disp_mem_height = 0;
    ft_MEM.disp_mem_width = 0;
    ft_MEM.pmem = malloc(1280*400*4);

    ft_MEM_SLV.cost_mem_width = 0;
    ft_MEM_SLV.disp_mem_height = 0;
    ft_MEM_SLV.disp_mem_width = 0;
    ft_MEM_SLV.pmem = malloc(1280*400*4);

    printf("fontfinish\n");

    return _FT_FONT_SUCC;
}
Ejemplo n.º 10
0
//播放器信号处理
int filter_av_engine_msg_process(ipcMsgQueueData_t *pmsg)
{
    int                 ret;

    ret = recvMsgQueueTimeOut(_AV_ENGINE_ID, pmsg, 0);
    if (ret <= 0)
    {
        return 0;
    }
#if 0
    switch (pmsg->msg_type)
    {
    case _av_engine_open:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "av engine open\r\n");
    }
    break;

    case _av_engine_start:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "av engine start\r\n");
    }
    break;

    case _av_engine_pause:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "av engine pause\r\n");
    }
    break;

    case _av_engine_close:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "av engine close\r\n");
    }
    break;

    case _av_engine_info:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "av engine information\r\n");
    }
    break;

    case _av_engine_aud_switch:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "av engine audio channel switch\r\n");
    }
    break;

    default:
    {
        M_TRACE(DEBUG_TRACE, AV_MODE, "default msg type\r\n");
    }
    break;
    }
#endif
    return 1;
}
Ejemplo n.º 11
0
MyDirectSound::~MyDirectSound()
{
	M_TRACE_FUNCTION;

	if( !m_createdBuffers.empty() )
	{
		M_TRACE("Deleting %d sound buffers\n", (int)m_createdBuffers.size());
		std::for_each( m_createdBuffers.begin(), m_createdBuffers.end(), delete_pointer<MyDirectSoundBuffer>() );
		m_createdBuffers.clear();
	}
	m_nextSoundBufferId = 0;
}
ULONG __stdcall MyDirectSoundBuffer::Release(void)
{  
	M_TRACE("%d: Release()\n", m_uniqueId);
    ULONG returnValue = InterlockedDecrement(&m_refCount);
    if (returnValue == 0)
    {
        // NOTE: all objects dependent on IDirectSoundBuffer* must be released.
		m_pDSoundDevice->RemoveBuffer(this);
		delete this;
    }
    return returnValue;
}
MyDirectSoundBuffer::~MyDirectSoundBuffer()
{
	//M_TRACE_FUNCTION;
	SAFE_RELEASE( m_pDSoundBuffer );

	if( m_alignedBuffer ) {
		M_TRACE("%d: Free 0x%p (%d bytes)\n", m_uniqueId, (void*)m_alignedBuffer, m_allocated);
		_aligned_free(m_alignedBuffer);
		m_alignedBuffer = 0;
	}
	m_allocated = 0;
	m_bytes = 0;
}
Ejemplo n.º 14
0
int init_send_udp_instance(udp_item_def *pHandle)
{
    struct sockaddr_in socketaddr;
    struct timeval timeout;

    //open a udp socket
    pHandle->socket_fp = socket(AF_INET, SOCK_DGRAM, 0);
    if (pHandle->socket_fp == -1)
    {
        M_TRACE(ERROR_TRACE, NET_MODE, "can not open the socket\r\n");
        return 0;
    }

    //set the timeout 1ms
    timeout.tv_sec = 0;
    timeout.tv_usec = 1000;
    setsockopt(pHandle->socket_fp,
               SOL_SOCKET, SO_SNDTIMEO,
               (const char*)&timeout,
               sizeof(timeout));

    //bind the socket and set the local port and ip address;
    socketaddr.sin_family = AF_INET;
    socketaddr.sin_port = htons(pHandle->near_port);
    socketaddr.sin_addr.s_addr = INADDR_ANY;
    memset(&(socketaddr.sin_zero), 0, 8);
    if (bind(pHandle->socket_fp,
             (struct sockaddr *) &(socketaddr),
             sizeof(struct sockaddr)) == -1)
    {
        M_TRACE(ERROR_TRACE, NET_MODE, "can not bind the socket\r\n");
        return 0;
    }

    M_TRACE(DEBUG_TRACE, NET_MODE, "init send udp instance success\r\n");
    return 1;
}
Ejemplo n.º 15
0
//继续播放
int resume_av_engine(void)
{
    int                 ret;
    ipcMsgQueueData_t   msg;

    memset(msg.msg_data, 0, IPC_MSG_DATA_MAX_LENGTH);
    msg.msg_type = av_engine_resume;

    ret = sendMsgQueue(AV_ENGINE_ID, &msg);
    if (ret < 0)
    {
        M_TRACE(WARING_TRACE, AV_MODE, "%d\r\n", ret);
    }

    return ret;
}
Ejemplo n.º 16
0
/// The DuplicateSoundBuffer method creates a new secondary buffer that shares the original buffer's memory.
/// pDSBufferOriginal - Address of the IDirectSoundBuffer or IDirectSoundBuffer8 interface of the buffer to duplicate.
/// ppDSBufferDuplicate - Address of a variable that receives the IDirectSoundBuffer interface pointer for the new buffer.
HRESULT __stdcall MyDirectSound::DuplicateSoundBuffer(THIS_ __in LPDIRECTSOUNDBUFFER pDSBufferOriginal, __deref_out LPDIRECTSOUNDBUFFER *ppDSBufferDuplicate)
{
#if 0//USE_SOUND_BUFFER_PROXY
	IDirectSoundBuffer* pDSBufferDuplicate = NULL;
	V_RET(m_pDSound->DuplicateSoundBuffer(pDSBufferOriginal, pDSBufferDuplicate));

	const int soundBufferId = m_nextSoundBufferId++;
	MyDirectSoundBuffer* pOriginal = static_cast< MyDirectSoundBuffer* >( pDSBufferOriginal );
	MyDirectSoundBuffer* pDuplicate = new MyDirectSoundBuffer( pcDSBufferDesc, pDSBuffer, this, soundBufferId );
	M_TRACE("DuplicateSoundBuffer(): %d -> %d (%d bytes)\n", soundBufferId, pOriginal->dwBufferBytes);
	return DS_OK;
#else
	M_TRACE_FREQUENT_FUNCTION;
	return m_pDSound->DuplicateSoundBuffer(pDSBufferOriginal, ppDSBufferDuplicate);
#endif
}
Ejemplo n.º 17
0
//交互音频音轨
int switch_aud_av_engine(int index)
{
    int                 ret;
    int                 pos;
    ipcMsgQueueData_t   msg;

    pos = av_engine_parameter_pos;

    memset(msg.msg_data, 0, IPC_MSG_DATA_MAX_LENGTH);
    memcpy(msg.msg_data+pos, &index, 4);
    msg.msg_type = av_engine_aud_switch;

    ret = sendMsgQueue(AV_ENGINE_ID, &msg);
    if (ret < 0)
    {
        M_TRACE(WARING_TRACE, AV_MODE, "%d\r\n", ret);
    }

    return ret;
}
Ejemplo n.º 18
0
/// The CreateSoundBuffer method creates a sound buffer object to manage audio samples. 
HRESULT __stdcall MyDirectSound::CreateSoundBuffer(THIS_ __in LPCDSBUFFERDESC pcDSBufferDesc, __deref_out LPDIRECTSOUNDBUFFER *ppDSBuffer, __null LPUNKNOWN pUnkOuter)
{
	M_ASSERT(pUnkOuter == NULL);
	// dwBufferBytes - Size of the new buffer, in bytes.
	// This value must be 0 when creating a buffer with the DSBCAPS_PRIMARYBUFFER flag.
	// For secondary buffers, the minimum and maximum sizes allowed are specified by DSBSIZE_MIN and DSBSIZE_MAX, defined in Dsound.h.
	const int soundBufferId = m_nextSoundBufferId++;
	M_TRACE("CreateSoundBuffer(): id = %d, dwBufferBytes = %d\n", soundBufferId, pcDSBufferDesc->dwBufferBytes);

#if USE_SOUND_BUFFER_PROXY

	IDirectSoundBuffer* pDSBuffer = NULL;
	V_RET(m_pDSound->CreateSoundBuffer(pcDSBufferDesc, &pDSBuffer, pUnkOuter));

	*ppDSBuffer = new MyDirectSoundBuffer( pcDSBufferDesc, pDSBuffer, this, soundBufferId );
	return DS_OK;

#else

	return m_pDSound->CreateSoundBuffer(pcDSBufferDesc, ppDSBuffer, pUnkOuter);

#endif
}
Ejemplo n.º 19
0
static int ft_Font_SetCharSize(int fontHeight, int fontWidth)
{
    int 	i, j, jppem;
    /* Font Lib Pixel Size Set */

    if (FT_IS_SCALABLE(ft_Font_FtFace))
    {
        M_TRACE(DEBUG_TRACE, FT_MODE, "FT_IS_SCALABLE(gFtFace)\r\n");
        if (FT_Set_Char_Size(ft_Font_FtFace, fontWidth*64, fontHeight*64, 0, 0))
        {
            M_TRACE(ERROR_TRACE, FT_MODE, "FT_Set_Char_Size Failed!\n");
            return _FT_FONT_FAIL;
        }
    }
    else
    {
        /* Fixed Size Select */
        jppem = ft_Font_FtFace->available_sizes[0].height;
        M_TRACE(DEBUG_TRACE, FT_MODE, "FtFace Fixed Size : %d \n", ft_Font_FtFace->num_fixed_sizes);
        for (i = 0, j = 0; i < ft_Font_FtFace->num_fixed_sizes; i++)
        {
            M_TRACE(DEBUG_TRACE, FT_MODE, "FtFace Height : %d \n", ft_Font_FtFace->available_sizes[i].height);

            if (fabs(ft_Font_FtFace->available_sizes[i].height-fontHeight) < abs(jppem-fontHeight))
            {
                jppem = ft_Font_FtFace->available_sizes[i].height;
                j = i;
            }
        }
        M_TRACE(DEBUG_TRACE, FT_MODE, "FtFace Fixed Select PPEM : %d \n", jppem);
        if (FT_Set_Pixel_Sizes(ft_Font_FtFace, ft_Font_FtFace->available_sizes[j].width, jppem))
        {
            M_TRACE(ERROR_TRACE, FT_MODE, "FT_Set_Pixel_Size Failed!\n");
            return _FT_FONT_FAIL;
        }
        fontHeight = jppem;
    }

    return fontHeight;
}
Ejemplo n.º 20
0
void display_info(void)
{
    Pixel64 FT;

    GrPos Pos;
    GrRegion Region;
    int ret;

    int id_length;
    int mac_length;

    char stb_id[64];
    char mac_id[64];
    char mac_id1[64];

    Pos.x = 520;
    Pos.y = 425;
    FT.RGB.a = 255;
    FT.RGB.r = 255;
    FT.RGB.g = 255;
    FT.RGB.b = 255;

    memset(stb_id, 0, 64);
    memset(mac_id, 0, 64);
    memset(mac_id1, 0, 64);
    display_character_into_screen(INFO_INPUT,
        FT,
        &Pos, &Region);

    while (1)
    {
        printf("input pcba sn:");
        scanf("%s", stb_id);
        printf("input pcba mac:");
        scanf("%s", mac_id);

        id_length = strlen(stb_id);
        mac_length = strlen(mac_id);

        M_TRACE(DEBUG_TRACE, SYS_MODE, "id = %d, mac = %d\n", id_length, mac_length);
        if ((id_length == 24) &&
            (mac_length == 12))
        {

            mac_id1[0] = mac_id[0];
            mac_id1[1] = mac_id[1];
            mac_id1[2] = ':';
            mac_id1[3] = mac_id[2];
            mac_id1[4] = mac_id[3];
            mac_id1[5] = ':';
            mac_id1[6] = mac_id[4];
            mac_id1[7] = mac_id[5];
            mac_id1[8] = ':';
            mac_id1[9] = mac_id[6];
            mac_id1[10] = mac_id[7];
            mac_id1[11] = ':';
            mac_id1[12] = mac_id[8];
            mac_id1[13] = mac_id[9];
            mac_id1[14] = ':';
            mac_id1[15] = mac_id[10];
            mac_id1[16] = mac_id[11];

            break;
        }

        memset(stb_id, 0, 64);
        memset(mac_id, 0, 64);
        memset(mac_id1, 0, 64);
    }


    /* 刘工bootm 怎么用*/
    set_pcba_mac(mac_id1);
    set_pcba_sn(stb_id);
}
Ejemplo n.º 21
0
//设置字符集
static int ft_Font_IconvCharSet(char* pSrc, int lenSrc, unsigned short **ppDst, int *pLenDst, char * pCharSet)
{
    iconv_t varConv;
    size_t 	lenIn, lenOut;
    int     lenDst = 0;
    char    *pOutHead, *pOut;

    *ppDst = NULL;

    /* Convert String */
    lenOut = (lenSrc+1024) * sizeof(short);
    lenIn = lenSrc;
    pOutHead = (char *)malloc(lenOut*sizeof(char));
    if (pOutHead == NULL)
    {
        M_TRACE(ERROR_TRACE, FT_MODE, ">>>>>>>>>>>>>>>memory leak\n");
        return _FT_FONT_FAIL;
    }

    /* Open iconv Lib */
    varConv = iconv_open("UCS-2-INTERNAL", pCharSet);
    if(varConv == (iconv_t)(_FT_FONT_FAIL))
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "Iconv Open %s Fail!\n", pCharSet);
        free(pOutHead);
        pOutHead = NULL;
        return _FT_FONT_FAIL;
    }

    memset(pOutHead, 0, lenOut*sizeof(char));
    pOut = pOutHead;
    while (lenIn > 0)
    {
        if((_FT_FONT_FAIL) == iconv(varConv, (char* *)(&pSrc), &lenIn,	&pOut, &lenOut))
        {
            M_TRACE(DEBUG_TRACE, FT_MODE, "Iconv ErrNo: %d!\n", errno);
            free(pOutHead);
            pOutHead = NULL;
            iconv_close(varConv);
            return _FT_FONT_FAIL;
        }
    }

    /* Convert '\0' */
    if((_FT_FONT_FAIL) == iconv(varConv, NULL, NULL, &pOut, &lenOut))
    {
        M_TRACE(DEBUG_TRACE, FT_MODE, "Iconv Str Fail!\n");
        free(pOutHead);
        pOutHead = NULL;
        iconv_close(varConv);
        return _FT_FONT_FAIL;
    }
    /* Set Size */
    lenDst = pOut -pOutHead;
    lenDst >>= 1;    /* Unicode Size */
    *pLenDst = lenDst;
    *ppDst = (unsigned short *)pOutHead;
    iconv_close(varConv);

    if(lenDst > 0)
    {
        //free(pOutHead);
        return _FT_FONT_SUCC;
    }

    free(pOutHead);
    pOutHead = NULL;
    return _FT_FONT_FAIL;
}
Ejemplo n.º 22
0
int ft_Font_Unicode_ToMem_with_const_width(short *pText,
        FT_MEM_BLOCK *pMem,
        unsigned int fontSize,
        unsigned long int mem_max_len,
        int uncode_len,
        int width,
        int *pout_len)
{
    FT_GlyphSlot        slot;
    FT_BitmapGlyph      bitmapGlyph;
    FT_Glyph            glyph;
    FT_Bitmap           *pBitmap = NULL;
    int                 glyph_index = 0;
    unsigned short      *pDstString = NULL;
    int                 dstLen = 0;
    int                 i, j, k;

    int mem_width = 0, mem_height = 0;
    int disp_mem_height = 0, width_tag = 0;

    unsigned char       *bitmapBuffer = NULL;
    int buffer_index, buffer_len;

    int ft_transform_active = 0;

    *pout_len = 0;
    bitmapBuffer = pMem->pmem;
    if(bitmapBuffer == NULL)
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "you haven't get memory!\n");
        return -1;
    }

    //memset(bitmapBuffer, 0, mem_max_len);
    pDstString = (unsigned short *) pText;
    dstLen = uncode_len;

    //set the char size
    if( _FT_FONT_FAIL == ft_Font_SetCharSize(fontSize, fontSize))
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "set free type size failure!\r\n");

        //ft_Font_FontConvStrBufRelease(pDstString);
        return -3;
    }

    mem_width = width;
    mem_height = fontSize*2;
    buffer_len = mem_height*mem_width;

    M_TRACE(DEBUG_TRACE, FT_MODE, "%d:%d:%d\r\n", mem_width, mem_height, buffer_len);
#if 1
    if(buffer_len >= mem_max_len)
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "not a usable mem block %d\n", buffer_len);

        //ft_Font_FontConvStrBufRelease(pDstString);
        return -4;
    }
#endif
    buffer_index = 0;
#if 0
    //memset(bitmapBuffer, 0, buffer_len*sizeof(TPPixel64));
    for(i = 0; i < buffer_len; i++)
    {
        bitmapBuffer[i] = 0x00;
    }
#endif

    for(i=0; i<dstLen; i++)
    {
        *pout_len = i+1;
        //get the index of current character and load glyph to slot
        glyph_index = FT_Get_Char_Index(ft_Font_FtFace, pDstString[i]);
        if(glyph_index==0)
        {
            //undefined character
            continue;
        }

        if(FT_Load_Glyph(ft_Font_FtFace, glyph_index, FT_LOAD_DEFAULT)!=0)
        {
            //load failure
            continue;
        }

        slot = ft_Font_FtFace->glyph;
        //if the slot format is not ft_glyph_format_bitmap, then render the glyph
        if(slot->format != ft_glyph_format_bitmap)
        {
            if(FT_Render_Glyph(ft_Font_FtFace->glyph, FT_RENDER_MODE_NORMAL) != 0)
            {
                //render failure
                continue;
            }
        }

        if(FT_Get_Glyph(slot, &glyph) != 0)
        {
            //get glyph failure
            continue;
        }

        ft_transform_active++;

        bitmapGlyph = (FT_BitmapGlyph)glyph;
        pBitmap = &(bitmapGlyph->bitmap);

        buffer_index = (fontSize-bitmapGlyph->top)*mem_width + bitmapGlyph->left + width_tag;

        for(j=0; j<pBitmap->rows;j++)
        {
            for(k=0;k<pBitmap->width;k++)
            {
                if(pBitmap->buffer[j*pBitmap->width+k] != 0)
                {
                    bitmapBuffer[buffer_index+j*mem_width+k] = pBitmap->buffer[j*pBitmap->width+k];
                }
            }
        }

        if((pBitmap->rows==0) && (pBitmap->width==0))
        {
            width_tag += TOP_FONT_GLYPH_SPACE;
        }
        else
        {
            width_tag += (bitmapGlyph->left+pBitmap->width);
        }

        if(disp_mem_height < (fontSize-bitmapGlyph->top+pBitmap->rows))
        {
            disp_mem_height = fontSize-bitmapGlyph->top+pBitmap->rows;
        }

        FT_Done_Glyph(glyph);

        //if (width_tag >= (width-(fontSize*2/3)) )

        if (width_tag >= (width-fontSize))
        {
            M_TRACE(DEBUG_TRACE, FT_MODE, "display width is enough %d %d\r\n", width_tag, width);
            break;
        }

    }

    if(ft_transform_active == 0)
    {
        //printf("[ft_error], there is not valid transform!\n");
        M_TRACE(ERROR_TRACE, FT_MODE, "there is not valid transform!\n");
        //ft_Font_FontConvStrBufRelease(pDstString);
        return -5;
    }

    M_TRACE(DEBUG_TRACE, FT_MODE, "[%d][%d][%d]\n",
                mem_width,
                disp_mem_height,
                width_tag);

    {

        int leave_taier = 0;
        int interval_num = 0;
        int insert_space = 1;
        int disp_font_num;

        disp_font_num = ft_transform_active;

        leave_taier = mem_width - width_tag;
        if (leave_taier > 4)
        {
            interval_num = (*pout_len + leave_taier-1)/leave_taier;
            M_TRACE(DEBUG_TRACE, FT_MODE, "modify now %d | %d\r\n", leave_taier, interval_num);
            mem_width = 0;
            mem_height = 0;
            disp_mem_height = 0;
            width_tag = 0;
            //*bitmapBuffer = NULL;

            ft_transform_active = 0;

            *pout_len = 0;
            bitmapBuffer = pMem->pmem;

            memset(bitmapBuffer, 0, mem_max_len);
            pDstString = (unsigned short *) pText;
            dstLen = uncode_len;

            mem_width = width;
            mem_height = fontSize*2;
            buffer_len = mem_height*mem_width;
            buffer_index = 0;

            for(i=0; i<dstLen; i++)
            {
                *pout_len = i+1;
                //get the index of current character and load glyph to slot
                glyph_index = FT_Get_Char_Index(ft_Font_FtFace, pDstString[i]);
                if(glyph_index==0)
                {
                    //undefined character
                    continue;
                }

                if(FT_Load_Glyph(ft_Font_FtFace, glyph_index, FT_LOAD_DEFAULT)!=0)
                {
                    //load failure
                    continue;
                }

                slot = ft_Font_FtFace->glyph;
                //if the slot format is not ft_glyph_format_bitmap, then render the glyph
                if(slot->format != ft_glyph_format_bitmap)
                {
                    if(FT_Render_Glyph(ft_Font_FtFace->glyph, FT_RENDER_MODE_NORMAL) != 0)
                    {
                        //render failure
                        continue;
                    }
                }

                if(FT_Get_Glyph(slot, &glyph) != 0)
                {
                    //get glyph failure
                    continue;
                }

                ft_transform_active++;

                bitmapGlyph = (FT_BitmapGlyph)glyph;
                pBitmap = &(bitmapGlyph->bitmap);

                buffer_index = (fontSize-bitmapGlyph->top)*mem_width + bitmapGlyph->left + width_tag;

                for(j=0; j<pBitmap->rows;j++)
                {
                    for(k=0;k<pBitmap->width;k++)
                    {
                        if(pBitmap->buffer[j*pBitmap->width+k] != 0)
                        {
                            bitmapBuffer[buffer_index+j*mem_width+k] = pBitmap->buffer[j*pBitmap->width+k];
                        }
                    }
                }

                if((pBitmap->rows==0) && (pBitmap->width==0))
                {
                    width_tag += TOP_FONT_GLYPH_SPACE;
                }
                else
                {
                    width_tag += (bitmapGlyph->left+pBitmap->width);
                }

                if(disp_mem_height < (fontSize-bitmapGlyph->top+pBitmap->rows))
                {
                    disp_mem_height = fontSize-bitmapGlyph->top+pBitmap->rows;
                }

                FT_Done_Glyph(glyph);

                if (disp_font_num == ft_transform_active)
                {
                    M_TRACE(DEBUG_TRACE, FT_MODE, "display finish %d|%d\r\n",
                        disp_font_num, ft_transform_active);
                    break;
                }

                if (insert_space*interval_num == i)
                {
                    M_TRACE(DEBUG_TRACE, FT_MODE, "inser space %d\r\n", i);

                    width_tag++;
                    insert_space++;

                }

                //if (width_tag >= (width-(fontSize*2/3)) )

            }

        }

    }


    pMem->cost_mem_width = mem_width;
    pMem->disp_mem_width = width_tag;
    pMem->disp_mem_height = disp_mem_height;

    M_TRACE(DEBUG_TRACE, FT_MODE, "[%d][%d][%d]\n",
        pMem->cost_mem_width,
        pMem->disp_mem_height,
        pMem->disp_mem_width);




    return 0;
}
Ejemplo n.º 23
0
int ft_Font_Unicode_ToMem(short *pText, FT_MEM_BLOCK *pMem, unsigned int fontSize, unsigned long int mem_max_len, int uncode_len)
{
    FT_GlyphSlot        slot;
    FT_BitmapGlyph      bitmapGlyph;
    FT_Glyph            glyph;
    FT_Bitmap           *pBitmap = NULL;
    int                 glyph_index = 0;
    unsigned short      *pDstString = NULL;
    int                 dstLen = 0;
    int                 i, j, k;

    int mem_width = 0, mem_height = 0;
    int disp_mem_height = 0, width_tag = 0;

    unsigned char       *bitmapBuffer = NULL;
    int buffer_index, buffer_len;

    int ft_transform_active = 0;

    bitmapBuffer = pMem->pmem;
    if(bitmapBuffer == NULL)
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "you haven't get memory!\n");
        return -1;
    }

    memset(bitmapBuffer, 0, mem_max_len);
    pDstString = (unsigned short *) pText;
    dstLen = uncode_len;

    //set the char size
    if( _FT_FONT_FAIL == ft_Font_SetCharSize(fontSize, fontSize))
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "set free type size failure!\r\n");

        //ft_Font_FontConvStrBufRelease(pDstString);
        return -3;
    }

    mem_width = dstLen*fontSize;
    mem_height = fontSize*2;
    buffer_len = mem_height*mem_width;

    if(buffer_len >= mem_max_len)
    {
        M_TRACE(ERROR_TRACE, FT_MODE, "not a usable mem block %d\n", buffer_len);

        //ft_Font_FontConvStrBufRelease(pDstString);
        return -4;
    }
    buffer_index = 0;

    //memset(bitmapBuffer, 0, buffer_len*sizeof(TPPixel64));
    for(i = 0; i < buffer_len; i++)
    {
        bitmapBuffer[i] = 0x00;
    }

    for(i=0; i<dstLen; i++)
    {
        //get the index of current character and load glyph to slot
        glyph_index = FT_Get_Char_Index(ft_Font_FtFace, pDstString[i]);
        if(glyph_index==0)
        {
            //undefined character
            continue;
        }

        if(FT_Load_Glyph(ft_Font_FtFace, glyph_index, FT_LOAD_DEFAULT)!=0)
        {
            //load failure
            continue;
        }

        slot = ft_Font_FtFace->glyph;
        //if the slot format is not ft_glyph_format_bitmap, then render the glyph
        if(slot->format != ft_glyph_format_bitmap)
        {
            if(FT_Render_Glyph(ft_Font_FtFace->glyph, FT_RENDER_MODE_NORMAL) != 0)
            {
                //render failure
                continue;
            }
        }

        if(FT_Get_Glyph(slot, &glyph) != 0)
        {
            //get glyph failure
            continue;
        }

        ft_transform_active++;

        bitmapGlyph = (FT_BitmapGlyph)glyph;
        pBitmap = &(bitmapGlyph->bitmap);

        buffer_index = (fontSize-bitmapGlyph->top)*mem_width + bitmapGlyph->left + width_tag;

        for(j=0; j<pBitmap->rows;j++)
        {
            for(k=0;k<pBitmap->width;k++)
            {
                if(pBitmap->buffer[j*pBitmap->width+k] != 0)
                {
                    bitmapBuffer[buffer_index+j*mem_width+k] = pBitmap->buffer[j*pBitmap->width+k];
                }
            }
        }

        if((pBitmap->rows==0) && (pBitmap->width==0))
        {
            width_tag += TOP_FONT_GLYPH_SPACE;
        }
        else
        {
            width_tag += (bitmapGlyph->left+pBitmap->width);
        }

        if(disp_mem_height < (fontSize-bitmapGlyph->top+pBitmap->rows))
        {
            disp_mem_height = fontSize-bitmapGlyph->top+pBitmap->rows;
        }

        FT_Done_Glyph(glyph);
    }

    if(ft_transform_active == 0)
    {
        //printf("[ft_error], there is not valid transform!\n");
        M_TRACE(ERROR_TRACE, FT_MODE, "there is not valid transform!\n");
        //ft_Font_FontConvStrBufRelease(pDstString);
        return -5;
    }

    pMem->cost_mem_width = mem_width;
    pMem->disp_mem_width = width_tag;
    pMem->disp_mem_height = disp_mem_height;

    M_TRACE(DEBUG_TRACE, FT_MODE, "[%d][%d][%d]\n",
        pMem->cost_mem_width,
        pMem->disp_mem_height,
        pMem->disp_mem_width);

    //free malloc
    //ft_Font_FontConvStrBufRelease(pDstString);
    return 0;
}
Ejemplo n.º 24
0
void ft_Font_Draw_2_Canvas(FT_MEM_BLOCK *pMem,
            Pixel64 *pCanvas,
            Pixel64 FT,
            GrPos Pos)
{
    int i, j;

    int disp_length ;
    int disp_height ;
    //	TPPixel64 *pSrcTPPixel;
    Pixel64 *pDstTPPixel;

    int srcAlpha = 0, dstAlpha = 0;

    if ((pMem == NULL) || (pCanvas == NULL))
        return ;

    if(pMem->disp_mem_width > screen_width)
    {
        disp_length = screen_width;
    }
    else
    {
        disp_length = pMem->disp_mem_width;
    }

    if (pMem->disp_mem_height > screen_height)
    {
        disp_height = screen_height;
    }
    else
    {
        disp_height = pMem->disp_mem_height;
    }

    pCanvas += (Pos.x + Pos.y *screen_width);

    M_TRACE(DEBUG_TRACE, FT_MODE, "[%d, %d]\n", disp_height, disp_length);
    for(i = 0; i < disp_height; i++)
    {
        for(j = 0; j < disp_length; j++)
        {
            //pSurface[i*1280+j].value32 = special_text_mem_block.pmem[i*special_text_mem_block.cost_mem_width+j].value32;
            FT.RGB.a = pMem->pmem[i*pMem->cost_mem_width+j];

            pDstTPPixel = pCanvas+i*screen_width+j;

            if(FT.RGB.a == 0xFF)
            {
                pDstTPPixel->value32 = FT.value32;
            }
            else if(FT.RGB.a > 0)
            {
                srcAlpha = FT.RGB.a;
                dstAlpha = 255 - FT.RGB.a;

                pDstTPPixel->RGB.r = (pDstTPPixel->RGB.r*dstAlpha + FT.RGB.r*srcAlpha)>>8;
                pDstTPPixel->RGB.g = (pDstTPPixel->RGB.g*dstAlpha + FT.RGB.g*srcAlpha)>>8;
                pDstTPPixel->RGB.b = (pDstTPPixel->RGB.b*dstAlpha + FT.RGB.b*srcAlpha)>>8;
            }
        }
    }