/**
 * @file hv_drv_OsdFont.h
 * @brief Osd driver layer font drawing interface.
 * @verbatim
 * ==============================================================================
 *                        ##### How to use this driver #####
 * ==============================================================================
 * (+) Use Hv_Drv_OsdFont_Init(...) to init font drawing data .
 * (+) Use Hv_Drv_OsdFont_DrawMenuFontList(...) to draw main menu fonts.
 * (+) Use Hv_Drv_OsdFont_DrawPunctuatedFontList(...) to draw INFO fonts.
 * (+) Use Hv_Drv_OsdFont_UpdateMenuFontList(...) to update menu fonts.
 * (+) Use Hv_Drv_OsdFont_HideMenuFontList(...) to hide menu fonts.
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 0.0.1
 * @date 2022-08-22
 */

#ifndef __HV_DRV_OSDFONT_H
#define __HV_DRV_OSDFONT_H

#include "hv_mw_OsdComm.h"
#include "hv_drv_OsdTypes.h"
#include "hv_comm_DataType.h"

#define OSD_REAL_FONTWIDTH(x) ((x) >= HV_OSD_CONFIG_COLUMN_MINWIDTH ? (x) : HV_OSD_CONFIG_COLUMN_MINWIDTH)

typedef OsdIndexColumn* (*pfDrawComponentFunc)(OsdRowInfo *pstRowInfo, OsdComponentNode *pstNode,
                                                OsdIndexColumn *pstColumn, BOOL bUpdate);
#if (HV_PROJECT_CONFIG_OSD_MARQUEE == HV_CONFIG_ON)
typedef BOOL (*pfMarqueeStepFunc)(OsdMarqueeNode *pstNode);
BOOL Hv_Drv_OsdFont_NeedMarquee(VOID);
VOID Hv_Drv_OsdFont_ResetMarquee(OsdComponentNode *pstNode);
VOID Hv_Drv_OsdFont_ResumeAll(OsdMarqueeDirection enDirection, INT32 iNextValue);
VOID Hv_Drv_OsdFont_ResetAll(VOID);
BOOL Hv_Drv_OsdFont_MarqueeNodeStep(OsdMarqueeNode *pstMarquee, BOOL bStepForward);
VOID Hv_Drv_OsdFont_StartMarquee(OsdComponentNode *pstNode);
VOID Hv_Drv_OsdFont_RemoveMarqueeNode(OsdMarqueeNode *pstMarquee);
VOID Hv_Drv_OsdFont_MarqueeMarkSlotsFreed(VOID);
VOID Hv_Drv_OsdFont_MarqueeStep(VOID);
VOID Hv_Drv_OsdFont_RemoveAutoMarqueeNodes(VOID);
VOID Hv_Drv_OsdFont_ResetAllMarqueeContents(VOID);

VOID Hv_Drv_OsdFont_MarqueeDebug(VOID);
#endif

#if (HV_PROJECT_CONFIG_OSD_TEXT_WRAPPING == HV_CONFIG_ON)
VOID Hv_Drv_OsdFont_RemoveAllWrapNodes(VOID);
#endif

/**
 * @brief Get font component's Y
 * @param[in] pstNode component node ptr
 * @return font Y
 */
USHORT16 Hv_Drv_OsdFont_GetComponentY(OsdComponentNode *pstNode);

/**
 * @brief Get font component's row num
 * @param[in] pstNode component node ptr
 * @return font row num
 */
UCHAR8 Hv_Drv_OsdFont_GetComponentRows(OsdComponentNode *pstNode);

/**
 * @brief Get font component's resource type
 * @param[in] pstNode component node ptr
 * @param[in] pusResourceSize component resource size
 * @param[in] pucBitType component resource bit
 * @return None
 */
VOID Hv_Drv_OsdFont_GetComponentResType(OsdComponentNode *pstNode, USHORT16 *pusResourceSize, UCHAR8 *pucBitType);

/**
 * @brief Get font management data of current window
 * @param[in] None
 * @return font management structure
 */
OsdPhyFontInfo* Hv_Drv_OsdFont_GetCurrentFontInfo(VOID);

/**
 * @brief set font display position
 * @param[in] usX X-axis value, offset within window
 * @param[in] usY Y-axis value, offset within window
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_SetFontStart(USHORT16 usX, USHORT16 usY);

/**
 * @brief font showing enable/disable function
 * @param[in] bEnable font showing enable or not
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_SetFontEnable(BOOL bEnable);

USHORT16 Hv_Drv_OsdFont_TakeCurrentSlot(OsdRowInfo *pstRowInfo, BOOL bIsUpdate);
/**
 * @brief get component's resource type
 * @param[in] pstNode component node ptr
 * @return resource type of component
 */
OsdResourceType Hv_Drv_OsdFont_GetComponentResourceType(OsdComponentNode *pstNode);

/**
 * @brief calculate component's box: x,y,width,height
 * @param[in] pstNode component node ptr
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_CalculateComponentBox(OsdComponentNode *pstNode, BOOL bFixupPosition);

/**
 * @brief Get rowInfo struct by Y-axis
 * @param[in] usY Y-axis value of the row, offset within window
 * @param[in] bInsert if insert if row not found
 * @return row structure if found or newly inserted, otherwise NULL
 */
OsdRowInfo* Hv_Drv_OsdFont_GetRowInfoByYaxis(USHORT16 usY, BOOL bInsert);

VOID Hv_Drv_OsdFont_FreeRangedRowSlots(OsdRowInfo *pstRowInfo, OsdIndexColumn *pstColumnStart, OsdIndexColumn *pstColumnEnd, BOOL bSkipCPUCanvas);

/**
 * @brief menu font components draw function
 * @param[in] pstWindow window of which to draw stFontShowListHead
 * @return HV_SUCCESS for success, HV_FAILURE for failure
 */
Status Hv_Drv_OsdFont_DrawMenuFontList(OsdWindow *pstWindow);

/**
 * @brief INFO font components draw function
 * @param[in] pstWindow window of which to draw Punctuated Text
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_DrawPunctuatedFontList(OsdWindow *pstWindow);

/**
 * @brief menu font components update function
 * @param[in] pstWindow window of which to update stFontShowListHead
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_UpdateMenuFontList(OsdWindow *pstWindow);

/**
 * @brief menu font components hide function
 * @param[in] pstWindow window of which to hide stFontDeleteListHead
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_HideMenuFontList(OsdWindow *pstWindow);

VOID Hv_Drv_OsdFont_FreeComponentDrawingmap(VOID);

UCHAR8* Hv_Drv_OsdFont_GetComponentDrawingmap(OsdComponentNode *pstNode, USHORT16 *pusTotalWidth, USHORT16 *pusTotalHeight);
Status Hv_Drv_OsdFont_GetFontResouceInfo(OsdComponentNode *pstNode, OsdFontResourceInfo *pstResInfo);

#if (HV_PROJECT_CONFIG_OSD_CUSTOM_GROUP_SUPPORT == HV_CONFIG_ON)
VOID Hv_Drv_OsdFont_PrepareCustomGroup(OsdComponent stCp, OsdCustomGroupInfo *pstCGInfo);
VOID Hv_Drv_OsdFont_RelocateAllCustomGroup(VOID);
VOID Hv_Drv_OsdFont_RemoveCustomGroup(OsdComponent stCp);
#endif

#if (HV_OSD_CONFIG_RESERVE_SLOTS_BYROW == HV_CONFIG_OFF)
/**
 * @brief get current drawing row catalog
 * @param[VOID] None
 * @return current row catalog structure
 */
OsdRowCatalog* Hv_Drv_OsdFont_GetCurrentCatalog(VOID);
#endif

#if (HV_PROJECT_CONFIG_OSD_CPU_CANVAS_SUPPORT == HV_CONFIG_ON)
Status Hv_Drv_OsdFont_ClearCPUCanvas(OsdComponentNode *pstComponent);
Status Hv_Drv_OsdFont_DrawCPUCanvasPoint(OsdComponentNode *pstComponent, USHORT16 usX, USHORT16 usY, UINT32 uiColor, BOOL bIsClear);
/*TODO fix here */
VOID Hv_Drv_OsdFont_CPUCanvasStep();
#endif

#if (HV_PROJECT_CONFIG_OSD_BIGFONT_SUPPORT == HV_CONFIG_ON)
VOID Hv_Drv_OsdFont_TestBigFont(VOID);
VOID Hv_Drv_OsdFont_TestBigFontBMP(VOID);
#endif

/**
 * @brief Osd Driver font init function
 * @param[in] None
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_Init(VOID);

#ifdef HV_SCALER_DEBUG_VERSION
extern USHORT16 g_usTotalComponentWidth;
extern USHORT16 g_usMaxComponentWidth;

/**
 * @brief Print osd font debug info
 * @param[in] None
 * @return VOID without return
 */
VOID Hv_Drv_OsdFont_DubugInfo(VOID);
VOID Hv_Drv_OsdFont_TestGroup(UCHAR8 ucGapWidth);
#endif

#endif
