/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2011 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstdimaging
 * Version: 1.02
 * First release date:   2011-02-03
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstdimaging library
 * 
 * mzstdimaging library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstdimaging library 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 the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#ifndef __MZSTDIMAGING_CANVAS_FILE_H__
#define __MZSTDIMAGING_CANVAS_FILE_H__

#include <windows.h>
#include "mzstdimagingCommon.h"
#include "mzObject.h"
#include "mzString.h"
#include "mzCanvas.h"

class DECLSPEC_MZSTDIMAGING CCanvasFile : public CObject {
public:
    WINAPI CCanvasFile();
    virtual WINAPI ~CCanvasFile();

    BOOL WINAPI drawJsonFile(CString fname, CCanvas* canvas);

protected:
    // array improving font management
    CArrayList* _cachedFonts;

    CFont* WINAPI getCachedFont(WCHAR* fontName, LONG fontSize, LONG fontColor);
    VOID WINAPI _commonInit();
    virtual VOID WINAPI _cleanup();
    VOID WINAPI _cleanCachedFonts();

private:
    // Variable valid only during call to drawJsonFile method.
    // It is set to canvas pointer and NULL-ed just before drawJsonFile method return.
    CCanvas* _canvasOperatedOn;

    VOID WINAPI getPageProperties(CStdObjectProperty* itemPage, float* width, float* height,
        float* marginLeft, float* marginTop, float* marginRight, float* marginBottom,
        CString* munits);
    VOID WINAPI getCommonShapeProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
        float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
        float* x, float* y, float* width, float* height,
        float* borderSize, CString* borderStyle, CString* borderColor, float* rotationAngle);
    VOID WINAPI getBorderProperties(CString prefix, CStdObjectProperty* itemShape,
        float* borderSize, CString* borderStyle, CString* borderColor);
    VOID WINAPI getBackgroundProperties(CString prefix, CStdObjectProperty* itemShape,
        CString* backgroundColor, CString* backgroundStyle, CString* backgroundHatchStyle);
    CFont* WINAPI getFontProperties(CString prefix, CStdObjectProperty* itemShape, CString* fontName, float* fontSize,
        CString* fontColor, CString* fontStyle);
    VOID WINAPI getRectProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
        float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
        float* x, float* y, float* width, float* height,
        float* borderSize, CString* borderStyle, CString* borderColor,
        CString* backgroundColor, CString* backgroundStyle, CString* backgroundHatchStyle,
        float* rotationAngle);
    CFont* WINAPI getTextProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
        float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
        float* x, float* y, float* width, float* height,
        CString* text, float* dxTextOffset, float* dyTextOffset,
        CString* fontName, float* fontSize, CString* fontStyle, CString* fontColor,
        float* borderSize, CString* borderStyle, CString* borderColor,
        CString* backgroundColor, CString* backgroundStyle, CString* backgroundHatchStyle,
        float* charSpacing, float* rotationAngle, CString* align, CString* valign,
        float* leftPadding, float* topPadding, float* rightPadding, float* bottomPadding);
    CFont* WINAPI getDateFieldProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
        float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
        float* x, float* y, float* width, float* height,
        CString* year, CString* month, CString *day, float* groupSpacing, float* fieldHeight,
        CString* fontName, float* fontSize, CString* fontColor, CString* fontStyle,
        float* borderSize, CString* borderColor, CString* borderStyle,
        CString* backgroundColor, CString* backgroundStyle, CString* backgroundHatchStyle,
        float* rotationAngle);
    VOID WINAPI getInputFieldProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
            float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
            float* x, float* y, float* width, float* height,
            CString* label, CString* text, BOOL* eachTextLetterInSeparateBox,
            CString* labelFontName, float* labelFontSize, CString* labelFontColor, CString* labelFontStyle,
            CString* textFontName, float* textFontSize, CString* textFontColor, CString* textFontStyle,
            float* labelOffsetY, float* labelPaddingLeft, float* labelPaddingTop, float* labelPaddingRight, float* labelPaddingBottom,
            float* labelLineBorderSize, CString* labelLineBorderStyle, CString* labelLineBorderColor,
            CString* labelLineBackgroundColor, CString* labelLineBackgroundStyle, CString* labelLineBackgroundHatch,
            float* borderSize, CString* borderStyle, CString* borderColor,
            CString* backgroundColor, CString* backgroundStyle, CString* backgroundHatchStyle,
            CString* textFieldBackgroundColor,
            float* textFieldBoxCount, float* textFieldSeparatorHeight, float* textFieldSeparatorThickness,
            float* rotationAngle,
            CFont** textFont, CFont** labelFont);
    CFont* WINAPI getTextInRectsProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
            float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
            float* x, float* y, float* width, float* height,
            CString* text,
            CString* textFontName, float* textFontSize, CString* textFontColor, CString* textFontStyle,
            float* borderSize, CString* borderStyle, CString* borderColor,
            CString* backgroundColor, CString* backgroundStyle, CString* backgroundHatchStyle,
            float* unitBorderSize, CString* unitBorderStyle, CString* unitBorderColor,
            CString* unitBackgroundColor, CString* unitBackgroundStyle, CString* unitBackgroundHatchStyle,
            float* unitWidth, float* unitHeight, float* unitPadding, float* spacing, BOOL* drawEmptyFields,
            float* rotationAngle);
    VOID WINAPI getLineProperties(CStdObjectProperty* itemShape, float parentWidth, float parentHeight,
        float parentMarginLeft, float parentMarginTop, float parentMarginRight, float parentMarginBottom,
        float* x, float* y, float* x2, float* y2, float* thickness, CString* style,
        CString* color, float* rotationAngle);

    LONG WINAPI stringStyleToPenStyle(CString style);
    ULONG WINAPI stringStyleToBrushStyle(CString style);
    ULONG_PTR WINAPI stringStyleToBrushHatchStyle(CString style);
};
typedef CCanvasFile* PCanvasFile;

#endif
