/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file u_txt.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This file exports all txt library specific definitions and structures.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_TXT Txt Browser
 *
 *  @ingroup groupMW
 *  @brief Provides constant,type definitions and function of the  Txt Lib
 *   ..  Txt Lib is a middleware component that is responsible for Txt decode
 *
 *  %MW Application API would be used by TV Application, lot of these APIs 
 *  would
 *   be wrapped from Exported API
 *
 *  @see groupMW
 *  @{
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_TXT_H_
#define _U_TXT_H_

#include "u_handle.h"
#include "u_lnk_list.h"

#define HT_TXT_TYPE         (HT_GROUP_IMG + 32)    /**<Txt handle        */

#define TXT_TYPE_DATA_NONE      ((UINT32)   0x00)    /**<  data none      */
#define TXT_TYPE_DATA_TAG       ((UINT32)   0x01)    /**<  tag data     */


typedef enum
{
    TXT_ASYNC_COND_SCANING = 0x0,
    TXT_ASYNC_COND_SCAN_FINISH,
    TXT_ASYNC_COND_SCAN_ABORT,
    TXT_ASYNC_COND_GET_DATA,
    TXT_ASYNC_COND_GET_DATA_FAIL,
    TXT_ASYNC_COND_MAX
} TXT_ASYNC_COND_T;

typedef VOID (*c_txt_nfy_fct) 
(                           HANDLE_T                h_handle,  /* (I) Specifies which handle will be notified. */
                            const VOID*             pv_tag,    /* (I) The client data specified by the client when callback has been called, the callback function will send it again.. */
                            TXT_ASYNC_COND_T        e_event,   /* (I) it identifies the event type of notification. */
                            const VOID*             pv_data
 );  /* (I) specify the notification data which is followed with the notification event. */


/*------------------------------------------------------------------*/
/*! @enum TXT_INTRA_TYPE_T
 *  @brief This structure enumerates all intra-Txt types.
 *  @code
 *  typedef enum
 *  {
 *      INTRA_TXT_THUMBNAIL_TYPE,
 *      INTRA_TXT_PRIMARY_TXT_TYPE
 *  } TXT_INTRA_TYPE_T;
 *  @endcode
 *  @li@c  INTRA_TXT_THUMBNAIL_TYPE                          - thumbnail type
 *  @li@c  INTRA_TXT_PRIMARY_TXT_TYPE                        - primary type
 */
/*------------------------------------------------------------------*/
typedef enum
{
    INTRA_TXT_THUMBNAIL_TYPE,
    INTRA_TXT_PRIMARY_TYPE
} TXT_INTRA_TYPE_T;

/*------------------------------------------------------------------*/
/*! @enum TXT_STOP_OP_TYPE_T
 *  @brief This structure enumerates all stop operation types.
 *  @code
 *  typedef enum
 *  {
 *      TXT_STOP_PRIMARY_OP_TYPE,
 *      TXT_STOP_THUMBNAIL_OP_TYPE
 *  } TXT_STOP_OP_TYPE_T;
 *  @endcode
 *  @li@c  TXT_STOP_PRIMARY_OP_TYPE                          - stop thumbnail type
 *  @li@c  TXT_STOP_THUMBNAIL_OP_TYPE                        - stop primary type
 */
/*------------------------------------------------------------------*/
typedef enum
{
    TXT_STOP_PRIMARY_OP_TYPE,
    TXT_STOP_THUMBNAIL_OP_TYPE
} TXT_STOP_OP_TYPE_T;

typedef enum
{
    TXT_STAT_INITIAL, 
    TXT_STAT_SCANING, 
    TXT_STAT_SCANED, 
    TXT_STAT_SCAN_ABORT,
    TXT_STAT_STOP,
    TXT_STAT_GET_DATA
} TXT_SCAN_STATUS_T;

typedef enum _TXT_CODE_TYPE_T
{
    TXT_ECODE_NONE = 0x0,                  // Txt code type
    /* 1. World  coding */
    TXT_ECODE_UTF8,
    TXT_ECODE_UTF8BE,
    TXT_ECODE_UNICODE,                     // UTF16
    TXT_ECODE_UNICODEBE,
    TXT_ECODE_UTF32,
    TXT_ECODE_UTF32BE,
    /* 2. Basic coding */
    TXT_ECODE_ASCII    = 0x7,              // USA character
    /* 3.1 Local coding 1 or 2 byte */
    TXT_ECODE_GB,                          // GB2312 simple chinese
    TXT_ECODE_BIG5,                        // BIG5 tradinal chinese
    TXT_ECODE_KSC,                         // Korean
    TXT_ECODE_JIS,                         // Japanese
    /* 3.2 Local coding 1 byte */
    TXT_ECODE_PL,                          // CP1250
    TXT_ECODE_RU,                          // CP1251
    TXT_ECODE_EN,                          // CP1252 ASCII[0X00-0XFF]
    TXT_ECODE_EL,                          // CP1253
    TXT_ECODE_TR,                          // CP1254
    TXT_ECODE_AR,                          // CP1256
    TXT_ECODE_HEBR,                        // CP1255
    TXT_ECODE_MAX
}TXT_ECODE_TYPE_T;


typedef enum _TXT_SET_ATTR_TYPE_T
{
    /*   none */
    TXT_SET_NONE= 0x0,   
    /*  1. text code */
    TXT_SET_ENCODE,                        
    /* 2.  text font */
    TXT_SET_WGL_HANDLE,
    /* 3. 1 is render base on line, default is base on page*/
    TXT_SET_RENDER_TYPE,
    /* 4. Set Scan Font Info*/
    TXT_SET_SCAN_FONT_INFO,
    /*  invalid  */
    TXT_SET_MAX
} TXT_SET_ATTR_TYPE_T;


typedef struct _TXT_SET_CMD_T
{
    TXT_SET_ATTR_TYPE_T e_set_attr_type;
    VOID* pv_param;
} TXT_SET_CMD_T;




/*------------------------------------------------------------------*/
/*! @enum TXT_SRC_TYPE_T
 *  @brief This structure enumerates all Txt source types.
 *  @code
 *  typedef enum
 *  {
 *      TXT_FILE_SRC_TYPE,
 *      TXT_MEMORY_SRC_TYPE,
 *      TXT_DLNA_SRC_TYPE
 *  } TXT_SRC_TYPE_T;
 *  @endcode
 *  @li@c  TXT_FILE_SRC_TYPE                                 - txt from file
 *  @li@c  TXT_MEMORY_SRC_TYPE                               - txt from memory
 *  @li@c  TXT_DLNA_SRC_TYPE                                 - txt from dlna
 */
/*------------------------------------------------------------------*/
typedef enum
{
    TXT_FILE_SRC_TYPE,
    TXT_MEMORY_SRC_TYPE,
    TXT_DLNA_SRC_TYPE
} TXT_SRC_TYPE_T;

#define MAX_PAGE_LINE 50

typedef struct _TXT_LINE_INFO_T
{
    DLIST_ENTRY_T(_TXT_LINE_INFO_T) t_line_lnk;
    UINT32                          ui4_offset_to_page_start;
    UINT16                          ui2_length;
    UINT32                          ui4_line_idx;
    #if 0
    UINT32                          ui4_logic_idx;
    BOOL                            b_logic_line;
    #endif
}TXT_LINE_INFO_T;

typedef struct _TXT_PAGE_INFO_T
{ 
    DLIST_ENTRY_T(_TXT_PAGE_INFO_T) t_page_lnk;
    DLIST_T(_TXT_LINE_INFO_T)        t_line_list;
    UINT32         ui4_offset_to_file_start;
    UINT16         ui2_page_lenth;
    UINT16         ui2_page_idx;
    UINT16         ui2_line_num;   
}TXT_PAGE_INFO_T;

typedef struct _TXT_DISPLAY_LINE_INFO_T
{
    DLIST_ENTRY_T(_TXT_DISPLAY_LINE_INFO_T) t_dis_line_lnk;
    UTF16_T*       w2s_string_start;
    UINT16         ui2_length;
    UINT32         ui4_line_idx;
    #if 0
    UINT32         ui4_logic_idx;
    BOOL           b_logic_line;
    #endif
}
TXT_DISPLAY_LINE_INFO_T;

typedef struct _TXT_DISPLAY_PAGE_INFO_T
{
    DLIST_ENTRY_T(_TXT_DISPLAY_PAGE_INFO_T) t_dis_page_lnk;
    DLIST_T(_TXT_DISPLAY_LINE_INFO_T) t_dis_line_list;
    UTF16_T*                w2s_string;
    UINT16                  ui2_page_idx;
    UINT16                  ui2_line_num;
}
TXT_DISPLAY_PAGE_INFO_T;

typedef struct
{
    INT32               i4_ret;
    VOID                *pv_tag;
} TXT_NFY_LOAD_WITH_TAG_T;



#define TXT_READ_FILE_MODE      ((UINT8) 0x01)    /**<  read file mode      */
#define TXT_RW_FILE_MODE        ((UINT8) 0x02)    /**<  read and write mode      */





/************************************************************************/
/* Error code                                                           */
/************************************************************************/
#define TXTR_MAX_SUPPORT            ((INT32)     4)    /**< Txt MAX Support       */
#define TXTR_NOT_ENOUGH_DATA        ((INT32)     3)    /**< Txt no data       */
#define TXTR_ALREADY_STOP           ((INT32)     2)    /**< Txt stop       */
#define TXTR_NO_EXIF_DATA           ((INT32)     1)    /**< no exif information       */
#define TXTR_OK                     ((INT32)     0)    /**< Txt ok       */
#define TXTR_MSG_Q_ERR              ((INT32)    -1)    /**< insufficient buffer       */
#define TXTR_FILE_OR_DIR_MISSING    ((INT32)    -2)    /**< file or directory is missing       */
#define TXTR_INV_HANDLE             ((INT32)    -3)    /**< invalid handle       */
#define TXTR_OUT_OF_HANDLE          ((INT32)    -4)    /**< out of handle       */
#define TXTR_OUT_OF_MEMORY          ((INT32)    -5)    /**< out of memory       */
#define TXTR_FCT_NOT_SUPPORT        ((INT32)    -6)    /**< function is not support       */
#define TXTR_DATA_NOT_INIT          ((INT32)    -7)    /**< name exist       */
#define TXTR_INV_ARG                ((INT32)    -8)    /**< invalid argument       */
#define TXTR_CMD_INV                ((INT32)    -9)    /**< Txt engine not found      */
#define TXTR_TXT_NOT_SUPPORT        ((INT32)   -10)    /**< Txt type not support       */
#define TXTR_INTERNAL_ERR           ((INT32)   -11)    /**< internal error       */
#define TXTR_REENTRY_LOADING        ((INT32)   -12)    /**< retry loading       */
#define TXTR_ABORT_SCAN             ((INT32)   -13)    /**< abort loading       */
#define TXTR_SCAN_FAIL              ((INT32)   -14)    /**< decode fail       */
#define TXTR_INITIAL_ERR            ((INT32)   -15)    /**< inital error       */
#define TXTR_FONT_NOT_INIT          ((INT32)   -16)    /**< message queue error       */
#define TXTR_FILE_ERR               ((INT32)   -17)    /**< file opration error       */
#define TXTR_CLI_ERROR              ((INT32)   -18)    /**< cli error       */
#define TXTR_AUTOFREE_ERROR         ((INT32)   -19)    /**< free resource error      */
#define TXTR_IO_ERROR               ((INT32)   -20)    /**< IO error       */
#define TXTR_DISPLAY_AREA_NOT_INIT  ((INT32)   -21)    /**< driver busy       */
#define TXTR_TXT_CRASHED            ((INT32)   -22)    /**< Txt crashed       */

/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/

#endif /* _U_TXT_H_ */
/*----------------------------------------------------------------------------*/
/*! @} */   /* end of  groupMW_TXT*/
/*----------------------------------------------------------------------------*/

