/*

CLASS {AL4_font|_csharp}, NATIVE, UNTESTED, BYTES :
IMPORT: {Font} .
IMPORT, ANYWAY: {AL4_drawing} .

NATIVE: "using System.Windows.Forms;" .
NATIVE: "using System.Drawing;" .
NATIVE: "///COPY AL4_font.cs" .

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;

using System.Runtime.InteropServices;

using AL4;
using AL4_project;

namespace AL4
{

public partial class AL4Form : Form
{
    
    //---------------------------------------------------------------- F O N T

    /*
    // Create FontEx object, return descriptor
    //---------------------------------------
    FUN Create_font({Font} F|ont_object, STR Face|_font,
        REAL Size|_font) ==> INT, NATIVE :
        "    RESULT = AL4Form.Do_Create_font(X_F, X_Face, X_Size);" .
    */
    public static int Do_Create_font(Ref_obj X_F, string X_Face, double X_Size)
    {
        FontEx F = new FontEx();
        if (X_Size < 0.01)
            F.Font = new System.Drawing.Font(X_Face, 10);
        else F.Font = new System.Drawing.Font(X_Face, (float)X_Size);

        int X = AllocDescriptor(F);
        F.Tag = X_F;
        return X;
    }

    /*
    // Destroy FontEx object
    //----------------------
    FUN Destroy_font(INT F|ont_handle), NATIVE :
        "     AL4Form.Do_Destroy_font((int)X_F);" .
    */
    public static void Do_Destroy_font(int X_F)
    {
        //FontEx F = (FontEx)All_descriptors[X_F];
        //F.Dispose();
        ReleaseDescriptor(X_F);
    }

    /*
    // Change font face and size
    //--------------------------
    //FUN Change_font_face_size(INT F|ont_handle, STR Face|_font,
    //    REAL Size|_font) ==> REAL, NATIVE :
    //    "RESULT = AL4Form.Do_Change_font_face_size(X_F, X_Face, X_Size);" .
    */
    public static double Do_Change_font_face_size(int X_F, string X_Face,
        double X_Size)
    {
        FontEx F = (FontEx)All_descriptors[X_F];
        if (X_Size <= 0) return F.Font.Size;
        F.Font = new System.Drawing.Font(X_Face, (float)X_Size, 
            F.Font.Style, GraphicsUnit.Point, F.Font.GdiCharSet);
        return F.Font.Size;
    }


    /*
    // Change font style
    //------------------
    //FUN Change_font_style(INT F|ont_handle,
    //    BOOL Styles|_font[{font_attr}])
    //    :
    //    -------------------------------------- 'convert font styles'
    //    INT fs|tyles_mask = 0
    //    CASE Styles['BOLD'] ? fs++ ;
    //    CASE Styles['ITALIC'] ? fs += 2 ;
    //    CASE Styles['UNDERLINE'] ? fs += 4 ;
    //    CASE Styles['STRIKE'] ? fs += 8 ;
    //    -------------------------------------- 'call font style change'
    //    Do_change_font_style(F, fs) .

    //FUN Do_change_font_style(INT F|ont_handle, INT Style|_value),
    //    NATIVE :
    //    "     AL4Form.Do_Change_font_style(X_F, X_Style);" .
    */
    public static void Do_Change_font_style(int X_F, int X_fs)
    {
        FontEx F = (FontEx)All_descriptors[X_F];
        FontStyle fs = System.Drawing.FontStyle.Regular;
        if ((X_fs & 1) != 0) fs |= System.Drawing.FontStyle.Bold;
        if ((X_fs & 2) != 0) fs |= System.Drawing.FontStyle.Italic;
        if ((X_fs & 4) != 0) fs |= System.Drawing.FontStyle.Underline;
        if ((X_fs & 8) != 0) fs |= System.Drawing.FontStyle.Strikeout;
        F.Font = new System.Drawing.Font(F.Font, fs);
    }

    /*
    // Change font charset and pitch
    //------------------------------
    //FUN Change_font_charset(INT F|ont_handle, INT Charset|_font),
    //    NATIVE :
    //    "     AL4Form.Do_Change_font_charset(X_F, X_Charset);" .
    */
    public static void Do_Change_font_charset(int X_F, int X_Charset)
    {
        FontEx F = (FontEx)All_descriptors[X_F];
        F.Font = new Font(F.Font.FontFamily, F.Font.Size, F.Font.Style, 
            GraphicsUnit.Point, (byte)X_Charset);
    }

}

}

/*
END
*/
