ApwFreetypeLibrary

Check-in [4f1061340c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial version.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4f1061340c82a9d420f39d415feb47ff5d3959f2
User & Date: arnulf 2014-12-29 21:43:01
Context
2014-12-29
21:43
initial version check-in: 8b3b803ceb user: arnulf tags: trunk
21:43
initial version. check-in: 4f1061340c user: arnulf tags: trunk
21:42
fixes and new files ftdemo/* check-in: b55b85d47e user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added ftcache/FTCBasicAttrRec.java.









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCBasicAttrRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicAttrRec extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicAttrRec";

    public FTCScalerRec scaler = null;
    public int load_flags = 0;

    /* ==================== FTCBasicAttrRec ================================== */
    public FTCBasicAttrRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCBasicFamilyRec.java.





















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCBasicFamilyRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicFamilyRec extends FTCFamilyRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicFamilyRec";

    public FTCBasicAttrRec attrs = null;

    /* ==================== FTCBasicFamilyRec ================================== */
    public FTCBasicFamilyRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== FTCBasicFamilyRec ================================== */
    public FTCBasicFamilyRec(FTCMruNodeRec mru_node) {
      super(mru_node);
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCBasicICacheClass.java.































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCBasicICacheClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicICacheClass extends FTCGCacheClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicICacheClass";

    /* ==================== FTCBasicICacheClass ================================== */
    public FTCBasicICacheClass() {
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCBasicICacheFuncs";
      this.node_type = FTCMruListClassRec.NODE_TYPE_FTC_INODE_REC;
      this.node_new           = new ftbase.FTInstanceMethod(class_name, "ftc_inode_new", 1);
      this.node_weight        = new ftbase.FTInstanceMethod(class_name, "ftc_inode_weight", 1);
      this.node_compare       = new ftbase.FTInstanceMethod(class_name, "ftc_gnode_compare", 1);
      this.node_remove_faceid = new ftbase.FTInstanceMethod(class_name, "ftc_basic_gnode_compare_faceid", 1);
      this.node_free          = new ftbase.FTInstanceMethod(class_name, "ftc_inode_free", 1);

      String class_name2 = "org.apwtcl.gles20.truetype.FTCCacheFuncs";
      this.cache_class_type = FTCCacheClassRec.FTC_CACHE_CLASS_TYPE_FTCBasicICacheClass;
      this.cache_init = new ftbase.FTInstanceMethod(class_name2, "ftc_gcache_init", 1);
      this.cache_done = new ftbase.FTInstanceMethod(class_name2, "ftc_gcache_done", 1);

      this.family_class = new FTCBasicIFamilyClass("FTCBasicICacheClass");
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

}

Added ftcache/FTCBasicICacheFuncs.java.































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;
  /* ===================================================================== */
  /*    FTCBasicICacheFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicICacheFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicICacheFuncs";
    
    /* ==================== FTCBasicICacheFuncs ================================== */
    public FTCBasicICacheFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_inode_new
     *
     * =====================================================================
     */
    public static int ftc_inode_new(Object ... args) {
      Log.w(TAG, "ftc_inode_new not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_inode_weight
     *
     * =====================================================================
     */
    public static int ftc_inode_weight(Object ... args) {
      Log.w(TAG, "ftc_inode_weight not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_gnode_compare
     *
     * =====================================================================
     */
    public static int ftc_gnode_compare(Object ... args) {
      Log.w(TAG, "ftc_gnode_compare not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_basic_gnode_compare_faceid
     *
     * =====================================================================
     */
    public static int ftc_basic_gnode_compare_faceid(Object ... args) {
      Log.w(TAG, "ftc_basic_gnode_compare_faceid not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_inode_free
     *
     * =====================================================================
     */
    public static int ftc_inode_free(Object ... args) {
      Log.w(TAG, "ftc_inode_free not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     * FTCImageCacheLookupScaler
     *
     * =====================================================================
     */
    public static int FTCImageCacheLookupScaler(Object cache,
            ftbase.FTReference<FTCScalerRec> scaler_ref, long load_flags, int gindex,
	        ftbase.FTReference<ftbase.FTGlyphRec> glyph_ref, ftbase.FTReference<FTCNodeRec> node_ref) {
      int error = 0;
      FTCBasicQueryRec query = new FTCBasicQueryRec();
      ftbase.FTGlyphRec glyph = glyph_ref.Get();
      FTCScalerRec scaler = null;
      FTCNodeRec node = null; /* make compiler happy */
      Object hash;

      /* some argument checks are delayed to FTC_Cache_Lookup */
      if (glyph_ref == null || glyph == null || scaler == null) {
        error = ftbase.FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      glyph_ref.Set(null);
      if (node_ref != null) {
        node_ref.Set(null);
      }
      /* FT_Load_Glyph(), FT_Load_Char() take FT_UInt flags */
//      if (load_flags > FT_UINT_MAX) {
//        FT_TRACE1(( "FTC_ImageCache_LookupScaler: higher bits in load_flags" ));
//        FT_TRACE1(( "0x%x are dropped\n", (load_flags & ~((FT_ULong)FT_UINT_MAX)) ));
//      }
      query.attrs.scaler = scaler;
      query.attrs.load_flags = (int)load_flags;
      hash = FTCHashFuncs.FTC_BASIC_ATTR_HASH(query.attrs) + gindex;
      error = FTCGCacheRec.FTCGCacheLookup((FTCGCacheRec)cache, (int)hash, gindex,
              (FTCGQueryRec)query, node_ref);
      if (error == 0) {
        glyph = ((FTCINodeRec)node).glyph;
        if (node_ref != null) {
          node_ref.Set(node);
          node.ref_count++;
        }
      }
      return error;
    }

}

Added ftcache/FTCBasicIFamilyClass.java.























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCBasicIFamilyClass                                               */
  /*                                                                       */
  /* in original code: ftc_basic_image_family_class                        */
  /* ===================================================================== */

public class FTCBasicIFamilyClass extends FTCIFamilyClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicIFamilyClass";

    /* ==================== FTCBasicIFamilyClass ================================ */
    public FTCBasicIFamilyClass(String initStr) {
      super(initStr);
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCCacheFuncs";
      this.node_type = FTCMruListClassRec.NODE_TYPE_FTC_BASIC_FAMILY_REC;
      this.node_compare = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_compare", 1);
      this.node_init = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_init", 1);
      this.node_reset = null;
      this.node_done = null;

      this.family_load_glyph = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_load_glyph", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

}

Added ftcache/FTCBasicIFamilyFuncs.java.

































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;

  /* ===================================================================== */
  /*    FTCBasicIFamilyFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicIFamilyFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicIFamilyFuncs";
    
    /* ==================== FTCBasicIFamilyFuncs ================================== */
    public FTCBasicIFamilyFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_basic_family_compare
     *
     * =====================================================================
     */
    public static int ftc_basic_family_compare(Object ... args) {
      Log.w(TAG, "ftc_basic_family_compare not yet implemented");

      int error = 0;

      return error;
    }

}

Added ftcache/FTCBasicQueryRec.java.









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCBasicQueryRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicQueryRec extends FTCGQueryRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicQueryRec";

    public FTCBasicAttrRec attrs = null;

    /* ==================== FTCBasicQueryRec ================================== */
    public FTCBasicQueryRec() {
      oid++;
      id = oid;
      attrs = new FTCBasicAttrRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCBasicSCacheClass.java.







































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;
  /* ===================================================================== */
  /*    FTCBasicSCacheClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicSCacheClass extends FTCGCacheClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicSCacheClass";

    /* ==================== FTCBasicSCacheClass ================================== */
    public FTCBasicSCacheClass() {
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCBasicSCacheFuncs";
      this.node_type = FTCMruListClassRec.NODE_TYPE_FTC_SNODE_REC;
      this.node_new = new ftbase.FTInstanceMethod(class_name, "ftc_snode_new", 1);
      this.node_weight = new ftbase.FTInstanceMethod(class_name, "ftc_snode_weight", 1);
      this.node_compare = new ftbase.FTInstanceMethod(class_name, "ftc_snode_compare", 1);
      this.node_remove_faceid = new ftbase.FTInstanceMethod(class_name, "ftc_basic_gnode_compare_faceid", 1);
      this.node_free = new ftbase.FTInstanceMethod(class_name, "ftc_snode_free", 1);

      String class_name2 = "org.apwtcl.gles20.truetype.FTCCacheFuncs";
      this.cache_class_type = FTCCacheClassRec.FTC_CACHE_CLASS_TYPE_FTCBasicSCacheClass;
      this.cache_init = new ftbase.FTInstanceMethod(class_name2, "ftc_gcache_init", 1);
      this.cache_done = new ftbase.FTInstanceMethod(class_name2, "ftc_gcache_done", 1);

      this.family_class = new FTCBasicSFamilyClass("FTCBasicSCacheClass");
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

    /* ==================== ftc_sbit_copy_bitmap ===================================== */
    public static int ftc_sbit_copy_bitmap (ftbase.FTReference<FTCSBitRec> sbit_ref, ftbase.FTBitmapRec bitmap) {
      int error = 0;
      int pitch = bitmap.pitch;
      long size;
      FTCSBitRec sbit = sbit_ref.Get();

      if (pitch < 0) {
        pitch = -pitch;
      }
      size = (long)( pitch * bitmap.rows);
      sbit.buffer = new byte[(int)size];
      if (sbit.buffer == null) {
        error = -999;
      } else {
        sbit.buffer = java.util.Arrays.copyOf(bitmap.buffer, (int)size);
        sbit_ref.Set(sbit);
      }
      return error;
    }
 
}

Added ftcache/FTCBasicSCacheFuncs.java.















































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;
  /* ===================================================================== */
  /*    FTCBasicSCacheFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicSCacheFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicSCacheFuncs";
    
    /* ==================== FTCBasicSCacheFuncs ================================== */
    public FTCBasicSCacheFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_snode_new
     *
     * =====================================================================
     */
    public static int ftc_snode_new(Object ... args) {
      ftbase.FTReference<FTCNodeRec> node_ref = (ftbase.FTReference<FTCNodeRec>)args[0];
      FTCNodeRec ftcsnode = node_ref.Get();
      Object ftcgquery = args[1];
      ftbase.FTReference<Object> cache_ref = (ftbase.FTReference<Object>)args[2];
      FTCCacheRec cache = (FTCCacheRec)cache_ref.Get();
      ftbase.FTReference<FTCSNodeRec> snode_ref = new ftbase.FTReference<FTCSNodeRec>();

Debug(0, DBG_CACHE, TAG, "ftc_snode_new");
      FTCSNodeRec snode = (FTCSNodeRec)ftcsnode;
      FTCGQueryRec gquery = (FTCGQueryRec) ftcgquery;

      int ret = FTCSNodeNew(snode_ref, gquery, cache);
      snode = snode_ref.Get();
      node_ref.Set((FTCNodeRec)snode);
      return ret;
    }

    /* =====================================================================
     *    ftc_snode_weight
     *
     * =====================================================================
     */
    public static int ftc_snode_weight(Object ... args) {
Debug(0, DBG_CACHE, TAG, "ftc_snode_weight");
      FTCNodeRec ftcsnode = (FTCNodeRec)args[0];
      FTCCacheRec cache = (FTCCacheRec)args[1];
      FTCSNodeRec snode = (FTCSNodeRec)ftcsnode;
      int count = snode.count;
      FTCSBitRec sbit;
      int sbitIdx = 0;
      int pitch;
      int size;

//      FT_ASSERT( snode.count <= FTC_SBIT_ITEMS_PER_NODE );
      /* the node itself */
      size = 20;  // FIXME have to check for size of FTCSNodeRec!! if it is necessary
      for ( ; count > 0; count--, sbitIdx++) {
        sbit = snode.sbits[sbitIdx];
        if (sbit.buffer != null) {
          pitch = sbit.pitch;
          if (pitch < 0) {
            pitch = -pitch;
          }
          /* add the size of a given glyph image */
          size += pitch * sbit.height;
        }
      }
      return size;
    }

    /* =====================================================================
     *    ftc_snode_compare
     *
     * =====================================================================
     */
    public static boolean ftc_snode_compare(Object ... args) {
Debug(0, DBG_CACHE, TAG, "ftc_snode_compare");
      FTCNodeRec ftcsnode = (FTCNodeRec)args[0];
      Object ftcgquery = (Object)args[1];
      FTCCacheRec cache = (FTCCacheRec)args[2];
      ftbase.FTReference<Boolean> list_changed_ref = (ftbase.FTReference<Boolean>)args[3];
      boolean list_changed = list_changed_ref.Get();
      FTCSNodeRec snode = (FTCSNodeRec)ftcsnode;
      FTCGQueryRec gquery = (FTCGQueryRec)ftcgquery;
      FTCGNodeRec gnode = (FTCGNodeRec)snode;
      int gindex = gquery.gindex;
      boolean result;

      if (list_changed_ref != null) {
        list_changed_ref.Set(false);
      }
      result = (gnode.family == gquery.family && (int)(gindex - gnode.gindex) < snode.count);
      if (result) {
        /* check if we need to load the glyph bitmap now */
        FTCSBitRec sbit = snode.sbits[(gindex - gnode.gindex)] ;

        /*
         *  The following code illustrates what to do when you want to
         *  perform operations that may fail within a lookup function.
         *
         *  Here, we want to load a small bitmap on-demand; we thus
         *  need to call the `ftc_snode_load' function which may return
         *  a non-zero error code only when we are out of memory (OOM).
         *
         *  The correct thing to do is to use @FTC_CACHE_TRYLOOP and
         *  @FTC_CACHE_TRYLOOP_END in order to implement a retry loop
         *  that is capable of flushing the cache incrementally when
         *  an OOM errors occur.
         *
         *  However, we need to `lock' the node before this operation to
         *  prevent it from being flushed within the loop.
         *
         *  When we exit the loop, we unlock the node, then check the `error'
         *  variable.  If it is non-zero, this means that the cache was
         *  completely flushed and that no usable memory was found to load
         *  the bitmap.
         *
         *  We then prefer to return a value of 0 (i.e., NO MATCH).  This
         *  ensures that the caller will try to allocate a new node.
         *  This operation consequently _fail_ and the lookup function
         *  returns the appropriate OOM error code.
         *
         *  Note that `buffer == NULL && width == 255' is a hack used to
         *  tag `unavailable' bitmaps in the array.  We should never try
         *  to load these.
         *
         */

        if (sbit.buffer == null && sbit.width == 255) {
          int size = 0;
          int error;
          ftbase.FTReference<Integer> size_ref = new ftbase.FTReference<Integer>();

          ftcsnode.ref_count++;  /* lock node to prevent flushing */
                                 /* in retry loop                 */
          size_ref.Set(size);
          error = ftc_snode_load(snode, cache.manager, gindex, size_ref);
          size = size_ref.Get();
          ftcsnode.ref_count--;  /* unlock the node */
          if (error != 0) {
            result = false;
          } else {
            list_changed_ref.Set(true);
            cache.manager.cur_weight += size;
          }
        }
      }
      return result;
    }

    /* =====================================================================
     *    ftc_basic_gnode_compare_faceid
     *
     * =====================================================================
     */
    public static int ftc_basic_gnode_compare_faceid(Object ... args) {
      Log.w(TAG, "ftc_basic_gnode_compare_faceid not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_snode_free
     *
     * =====================================================================
     */
    public static int ftc_snode_free(Object ... args) {
      Log.w(TAG, "ftc_snode_free not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     * FTCSCacheLookupScaler
     *
     * =====================================================================
     */
    public static int FTCSCacheLookupScaler(FTCGCacheRec cache,
           ftbase.FTReference<FTCScalerRec> scaler_ref, long load_flags, int gindex,
           ftbase.FTReference<FTCSBitRec> sbit_ref, ftbase.FTReference<FTCNodeRec> node_ref) {
      int error = 0;
      FTCScalerRec scaler = scaler_ref.Get();
      FTCBasicQueryRec query = new FTCBasicQueryRec();
      FTCNodeRec node = null; /* make compiler happy */
      Object hash;
      FTCSBitRec sbit = sbit_ref.Get();
      boolean had_node_lst = true;
      
      if (node_ref == null) {
        had_node_lst = false;
        node_ref = new ftbase.FTReference<FTCNodeRec>();
      }
Debug(0, DBG_CACHE, TAG, "FTCSBitCacheLookupScaler cache: "+cache+"!"+cache.families.data+"!");
      if (node_ref != null) {
          node_ref.Set(null);
      }
      /* other argument checks delayed to FTC_Cache_Lookup */
      if (sbit_ref == null || scaler_ref == null) {
          return ftbase.FTError.GLYPH_INVALID_ARGUMENT;
      }
      /* FT_Load_Glyph(), FT_Load_Char() take FT_UInt flags */
//      if (load_flags > FT_UINT_MAX) {
//        FT_TRACE1(( "FTC_ImageCache_LookupScaler: higher bits in load_flags" ));
//        FT_TRACE1(( "0x%x are dropped\n", (load_flags & ~((FT_ULong)FT_UINT_MAX)) ));
//      }
      query.attrs.scaler = scaler;
      query.attrs.load_flags = (int)load_flags;
      /* beware, the hash must be the same for all glyph ranges! */
      hash = FTCHashFuncs.FTC_BASIC_ATTR_HASH(query.attrs) + gindex / FTCSNodeRec.FTC_SBIT_ITEMS_PER_NODE;
Debug(0, DBG_CACHE, TAG, "FTCSBitCacheLookupScaler cache: "+((FTCCacheRec)cache).toDebugString());
      error = FTCGCacheRec.FTCGCacheLookup(cache, (int)hash, gindex, (FTCGQueryRec)query, node_ref);
      node = node_ref.Get();
      if (error != 0) {
        return error;
      }
      sbit = ((FTCSNodeRec)node).sbits[gindex - ((FTCGNodeRec)node).gindex];
      sbit_ref.Set(sbit);
      if (node_ref != null && had_node_lst) {
        node_ref.Set(node);
        node.ref_count++;
      }
      return error;
    }

    /* =====================================================================
     * FTCSNodeNew
     *
     * =====================================================================
     */
    public static int FTCSNodeNew(ftbase.FTReference<FTCSNodeRec> snode_ref, FTCGQueryRec gquery, Object cache) {
Debug(0, DBG_CACHE, TAG, "FTCSNodeNew");
      int error = 0;
      FTCSNodeRec snode = null;
      int gindex = gquery.gindex;
      FTCFamilyRec family = gquery.family;
      ftbase.FTReference<FTCFamilyRec> family_ref = new ftbase.FTReference<FTCFamilyRec>();
      ftbase.FTReference<FTCGNodeRec> gnode_ref = new ftbase.FTReference<FTCGNodeRec>();
      int total;
      int node_count;
      FTCGCacheRec my_cache = (FTCGCacheRec)cache;
      FTCBasicSCacheClass my_class = (FTCBasicSCacheClass)(my_cache.clazz);

      total = (int)((FTCBasicSFamilyClass)(my_class.family_class)).family_get_count.callClassMethod(family, my_cache.manager);
      if (total == 0 || gindex >= total) {
        error = ftbase.FTError.GLYPH_INVALID_ARGUMENT;
        snode_ref.Set(snode);
        return error;
      }
      snode = new FTCSNodeRec();
        int count;
        int start;

        start = gindex - (gindex % FTCSNodeRec.FTC_SBIT_ITEMS_PER_NODE);
        count = total - start;
        if (count > FTCSNodeRec.FTC_SBIT_ITEMS_PER_NODE) {
          count = FTCSNodeRec.FTC_SBIT_ITEMS_PER_NODE;
        }
        family_ref.Set(family);
        gnode_ref.Set((FTCGNodeRec)snode);
        FTCGNodeInit(gnode_ref, start, family_ref);
        family = family_ref.Get();
        snode = (FTCSNodeRec)gnode_ref.Get();
        snode.count = count;
        for (node_count = 0; node_count < count; node_count++) {
          snode.sbits[node_count].width = 255;
        }
        error = ftc_snode_load(snode, my_cache.manager, gindex, null);
        if (error != 0) {
//          FTCSNodeFree(snode, cache);
          snode = null;
        }
      snode_ref.Set(snode);
      return error;
    }

    /* =====================================================================
     * FTCGNodeInit
     *
     * =====================================================================
     */
    public static int FTCGNodeInit(ftbase.FTReference<FTCGNodeRec> gnode_ref, int gindex, ftbase.FTReference<FTCFamilyRec> family_ref) {
      FTCGNodeRec gnode = gnode_ref.Get();
      FTCFamilyRec family = family_ref.Get();
      int error = 0;

Debug(0, DBG_CACHE, TAG, "FTCGNodeInit");
      gnode.family = family;
      gnode.gindex = gindex;
      family.num_nodes++;
      gnode_ref.Set(gnode);
      family_ref.Set(family);
      return error;
    }

    private static boolean CHECK_CHAR(int d) {
      char temp;
      temp = (char)d;
      return temp == d;
    }
    
    private static boolean CHECK_BYTE(int d) {
      byte temp;
      temp = (byte)d;
      return temp == d;    	
    }
      
    /* =====================================================================
     * ftc_snode_load
     *
     * =====================================================================
     */
    public static int ftc_snode_load(FTCSNodeRec snode, FTCManagerRec manager, int gindex, ftbase.FTReference<Integer> size_ref) {
      int error = 0;
      FTCGNodeRec gnode = (FTCGNodeRec)snode;
      FTCFamilyRec family = gnode.family;
      ftbase.FTFaceRec face = null;
      FTCSBitRec sbit;
      FTCBasicSCacheClass clazz;

Debug(0, DBG_CACHE, TAG, "ftc_snode_load");
      if ((int)(gindex - gnode.gindex) >= snode.count) {
        Log.e(TAG, "ftc_snode_load: invalid glyph index" );
        return ftbase.FTError.GLYPH_INVALID_ARGUMENT;
      }
      sbit = snode.sbits[(gindex - gnode.gindex)];
      clazz = (FTCBasicSCacheClass)gnode.family.cache.clazz;
      sbit.buffer = null;
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = new ftbase.FTReference<ftbase.FTFaceRec>();
      face_ref.Set(face);
      error = (int)((FTCBasicSFamilyClass)(clazz.family_class)).family_load_glyph.callClassMethod(family, gindex, manager, face_ref);
      face = face_ref.Get();
      if (error != 0) {
        sbit.width = 255;
        sbit.height = 0;
        sbit.buffer = null;
        error = ftbase.FTError.INTERP_ERR_OK;
        if (size_ref != null) {
          size_ref.Set(null);
        }
        return error;
      }
      {
        ftbase.FTGlyphSlotRec slot = face.glyph;
        ftbase.FTBitmapRec bitmap = slot.bitmap;
        long xadvance, yadvance; /* FT_GlyphSlot.advance.{x|y} */

        if (slot.format != FT_GLYPH_FORMAT_BITMAP) {
          ftbase.FTTrace.Trace(7, TAG, "ftc_snode_load: glyph loaded didn't return a bitmap");
          sbit.width = 255;
          sbit.height = 0;
          sbit.buffer = null;
          error = ftbase.FTError.INTERP_ERR_OK;
          if (size_ref != null) {
            size_ref.Set(null);
          }
          return error;
        }
        /* Check that our values fit into 8-bit containers!       */
        /* If this is not the case, our bitmap is too large       */
        /* and we will leave it as `missing' with sbit.buffer = 0 */
        /* horizontal advance in pixels */
        xadvance = (slot.advance.x + 32) >> 6;
        yadvance = (slot.advance.y + 32) >> 6;
        if (!CHECK_BYTE(bitmap.rows) ||
            !CHECK_BYTE(bitmap.width) ||
            !CHECK_CHAR(bitmap.pitch) ||
            !CHECK_CHAR(slot.bitmap_left) ||
            !CHECK_CHAR(slot.bitmap_top) ||
            !CHECK_CHAR((int)xadvance) ||
            !CHECK_CHAR((int)yadvance)) {
          ftbase.FTTrace.Trace(7, TAG, "ftc_snode_load: glyph too large for small bitmap cache");
          sbit.width = 255;
          sbit.height = 0;
          sbit.buffer = null;
          error = ftbase.FTError.INTERP_ERR_OK;
          if (size_ref != null) {
            size_ref.Set(null);
          }
          return error;
        }
        sbit.width = (short)bitmap.width;
        sbit.height = (short)bitmap.rows;
        sbit.pitch = (short)bitmap.pitch;
        sbit.left = (short)slot.bitmap_left;
        sbit.top = (short)slot.bitmap_top;
        sbit.xadvance = (short)xadvance;
        sbit.yadvance = (short)yadvance;
        sbit.format = (byte)bitmap.pixel_mode;
        sbit.max_grays = (short)(bitmap.num_grays - 1);
        /* copy the bitmap into a new buffer -- ignore error */
        ftbase.FTReference<FTCSBitRec> sbit_ref = new ftbase.FTReference<FTCSBitRec>();
        sbit_ref.Set(sbit);
        error = FTCBasicSCacheClass.ftc_sbit_copy_bitmap(sbit_ref, bitmap);
        sbit = sbit_ref.Get();
        /* now, compute size */
        if (size_ref != null) {
          size_ref.Set((int)(ftbase.FTCalc.FT_ABS((long)sbit.pitch) * sbit.height));
        }
      } /* glyph loading successful */
      /* ignore the errors that might have occurred --   */
      /* we mark unloaded glyphs with `sbit.buffer == 0' */
      /* and `width == 255', `height == 0'               */
      /*                                                 */
      if (error != 0 && error != ftbase.FTError.GLYPH_OUT_OF_MEMORY) {
        sbit.width = 255;
        sbit.height = 0;
        sbit.buffer = null;
        error = ftbase.FTError.INTERP_ERR_OK;
        if (size_ref != null) {
          size_ref.Set(null);
        }
      }
      return error;
    }

}

Added ftcache/FTCBasicSFamilyClass.java.























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCBasicSFamilyClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicSFamilyClass extends FTCSFamilyClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicSFamilyClass";

    /* ==================== FTCBasicSFamilyClass ================================== */
    public FTCBasicSFamilyClass(String initStr) {
      super(initStr);
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCCacheFuncs";
      this.node_type = FTCMruListClassRec.NODE_TYPE_FTC_BASIC_FAMILY_REC;
      this.node_compare = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_compare", 1);
      this.node_init = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_init", 1);
      this.node_reset = null;
      this.node_done = null;

      this.family_get_count = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_get_count", 1);
      this.family_load_glyph = new ftbase.FTInstanceMethod(class_name, "ftc_basic_family_load_bitmap", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

}

Added ftcache/FTCBasicSFamilyFuncs.java.

































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;

  /* ===================================================================== */
  /*    FTCBasicSFamilyFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCBasicSFamilyFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCBasicSFamilyFuncs";
    
    /* ==================== FTCBasicSFamilyFuncs ================================== */
    public FTCBasicSFamilyFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_basic_family_compare
     *
     * =====================================================================
     */
    public static int ftc_basic_family_compare(Object ... args) {
      Log.w(TAG, "ftc_basic_family_compare not yet implemented");

      int error = 0;

      return error;
    }

}

Added ftcache/FTCCMapCacheClass.java.

























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCCMapCacheClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCCMapCacheClass extends FTCCacheClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCMapCacheClass";

    /* ==================== FTCCMapCacheClass ================================== */
    public FTCCMapCacheClass() {
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCCMapCacheFuncs";
      this.node_new = new ftbase.FTInstanceMethod(class_name, "ftc_cmap_node_new", 1);
      this.node_weight = new ftbase.FTInstanceMethod(class_name, "ftc_cmap_node_weight", 1);
      this.node_compare = new ftbase.FTInstanceMethod(class_name, "ftc_cmap_node_compare", 1);
      this.node_remove_faceid = new ftbase.FTInstanceMethod(class_name, "ftc_cmap_node_remove_faceid", 1);
      this.node_free = new ftbase.FTInstanceMethod(class_name, "ftc_cmap_node_free", 1);

      this.cache_class_type = FTCCacheClassRec.FTC_CACHE_CLASS_TYPE_FTCCMapCacheClass;
      String class_name2 = "org.apwtcl.gles20.truetype.FTCCacheRec";
      this.cache_init = new ftbase.FTInstanceMethod(class_name2, "ftc_cache_init", 1);
      this.cache_done = new ftbase.FTInstanceMethod(class_name2, "ftc_cache_done", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

}

Added ftcache/FTCCMapCacheFuncs.java.



























































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;

import ftbase.FTCharMapRec;
  /* ===================================================================== */
  /*    FTCCMapCacheFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCCMapCacheFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCMapCacheFuncs";
    
    /* ==================== FTCCMapCacheFuncs ================================== */
    public FTCCMapCacheFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    FTCCMapCacheLookup
     *
     * =====================================================================
     */
    public static int FTCCMapCacheLookup(FTCCacheRec cmap_cache,
           Object face_id, int cmap_index, int char_code) {
      FTCCacheRec cache = (FTCCacheRec)cmap_cache;
      FTCCMapQueryRec query = new FTCCMapQueryRec();
      FTCNodeRec node = null;
      int error;
      int gindex = 0;
      Object hash;
      int no_cmap_change = 0;
  
  
Debug(0, DBG_CACHE, TAG, String.format("FTC_CMapCache_Lookup: cmap_index: %d, char_code: %c 0x%02x", cmap_index, char_code, char_code));
      if (cmap_index < 0) {
        /* Treat a negative cmap index as a special value, meaning that you */
        /* don't want to change the FT_Face's character map through this    */
        /* call.  This can be useful if the face requester callback already */
        /* sets the face's charmap to the appropriate value.                */
  
        no_cmap_change = 1;
        cmap_index = 0;
      }
      if (cache == null) {
        ftbase.FTTrace.Trace(7, TAG, "FTC_CMapCache_Lookup: bad arguments, returning 0");
        return 0;
      }
      query.face_id = face_id;
      query.cmap_index = cmap_index;
      query.char_code = char_code;
      hash = FTCHashFuncs.FTC_CMAP_HASH(face_id, cmap_index, char_code);
      ftbase.FTReference<FTCCMapQueryRec> query_ref = new ftbase.FTReference<FTCCMapQueryRec>();
      ftbase.FTReference<FTCNodeRec> node_ref = new ftbase.FTReference<FTCNodeRec>();
      query_ref.Set(query);
      node_ref.Set(node);
      error = FTCCacheRec.FTCCacheLookup(cache, hash, query_ref, node_ref);
      node = node_ref.Get();
      query = query_ref.Get();
      if (error != 0) {
        return gindex;
      }
//      FT_ASSERT( (int)(char_code - ((FTCCMapNodeRec)node).first ) <
//                  FTCCMapNodeRec.FTC_CMAP_INDICES_MAX);
      /* something rotten can happen with rogue clients */
      int val1 = char_code - ((FTCCMapNodeRec)node).first;
      int val2 = FTCCMapNodeRec.FTC_CMAP_INDICES_MAX;
      if (val1 >= val2) {
//FIXME!!        return 0; /* XXX: should return appropriate error */
     } 
      gindex = ((FTCCMapNodeRec)node).indices[val1];
      if (gindex == FTCCMapNodeRec.FTC_CMAP_UNKNOWN) {
        ftbase.FTFaceRec face;
  
        gindex = 0;
        ftbase.FTReference<ftbase.FTFaceRec> face_ref = new ftbase.FTReference<ftbase.FTFaceRec>();
        error = FTCManagerRec.FTCManagerLookupFace(cache.manager, ((FTCCMapNodeRec)node).face_id, face_ref);
        face = face_ref.Get();
        if (error != 0) {
          return gindex;
        }
        if ((int)cmap_index < (int)face.num_charmaps) {
          FTCharMapRec old = null;
          FTCharMapRec cmap = null;
  
          old  = face.charmap;
          cmap = face.charmaps[cmap_index];
          if (old != cmap && (no_cmap_change == 0)) {
            FTSetCharmap(face, cmap);
          } 
          gindex = FTCharMapRec.FTGetCharIndex(face, char_code);
          if (old != cmap && (no_cmap_change == 0)) {
            FTSetCharmap(face, old);
          }
        }
        ((FTCCMapNodeRec)node).indices[char_code - ((FTCCMapNodeRec)node).first] = gindex;
      }
      return gindex;
    }
 
    /* =====================================================================
     *    FTSetCharMap
     *
     * =====================================================================
     */
    public static int FTSetCharmap(ftbase.FTFaceRec face, FTCharMapRec charmap) {
      FTCharMapRec cur[];
      int curIdx = 0;
      int limit;
  
  
      if (face == null) {
        return ftbase.FTError.GLYPH_INVALID_FACE_HANDLE;
      }
      cur = face.charmaps;
      if (cur == null) {
        return ftbase.FTError.CMAP_INVALID_CHARMAP_HANDLE;
      }
      if (FTGetCMapFormat(charmap) == 14)
        return ftbase.FTError.GLYPH_INVALID_ARGUMENT;
  
      limit = face.num_charmaps;
  
      for (curIdx = 0; curIdx < limit; curIdx++) {
        if (cur[curIdx] == charmap) {
          face.charmap = cur[curIdx];
          return 0;
        }
      }
      return ftbase.FTError.GLYPH_INVALID_ARGUMENT;
    }

    /* =====================================================================
     *    FTGetCMapFormat
     *
     * =====================================================================
     */
    public static long FTGetCMapFormat(FTCharMapRec charmap) {
      FTServiceTTCMapsRec service;
      ftbase.FTFaceRec face;
      TTCMapInfoRec cmap_info;
  
  
      if (charmap == null || charmap.face == null) {
        return -1;
      }
      face = charmap.face;
      ftbase.FTModuleRec module = ((ftbase.FTModuleRec)face.driver);
      service = (FTServiceTTCMapsRec)module.module_clazz.get_interface.callClassMethod(module, "TT_CMAP");
//      FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
      if (service == null) {
        return -1;
      }
      FTReference<TTCMapInfoRec> cmap_info_ref = new FTReference<TTCMapInfoRec>();
      if ((int)service.get_cmap_info.callClassMethod(charmap, cmap_info_ref) == 0) {
        return -1;
      }
      cmap_info = cmap_info_ref.Get();
      return cmap_info.format;
    }

    /* =====================================================================
     *    ftc_cmap_node_new
     *
     * =====================================================================
     */
    public static int ftc_cmap_node_new(Object ... args) {
      ftbase.FTReference<FTCNodeRec> node_ref = (ftbase.FTReference<FTCNodeRec>)args[0];
      ftbase.FTReference<FTCCMapQueryRec> ftcquery = (ftbase.FTReference<FTCCMapQueryRec>)args[1];
      ftbase.FTReference<FTCGCacheRec> cache_ref = (ftbase.FTReference<FTCGCacheRec>)args[2];
      FTCCacheRec cache = (FTCCacheRec)cache_ref.Get();
      FTCCMapQueryRec query = (FTCCMapQueryRec)ftcquery.Get();
      int error = 0;
      FTCCMapNodeRec node = null;
      int nn;

      node = new FTCCMapNodeRec();
      node.face_id = query.face_id;
      node.cmap_index = query.cmap_index;
      node.first = (query.char_code / FTCCMapNodeRec.FTC_CMAP_INDICES_MAX) * FTCCMapNodeRec.FTC_CMAP_INDICES_MAX;
      for (nn = 0; nn < FTCCMapNodeRec.FTC_CMAP_INDICES_MAX; nn++) {
        node.indices[nn] = FTCCMapNodeRec.FTC_CMAP_UNKNOWN;
      } 
      node_ref.Set(node);
      return error;
    }

    /* =====================================================================
     *    ftc_cmap_node_weight
     *
     * =====================================================================
     */
    public static int ftc_cmap_node_weight(Object ... args) {
      FTCCMapNodeRec cnode = (FTCCMapNodeRec)args[0];
      FTCGCacheRec cache = (FTCGCacheRec)args[1];
      Log.w(TAG, "ftc_cmap_node_weight not fully implemented");
      return 0; /* should be some amount of memory for determining FTCCMapNodeRec */
    }

    /* =====================================================================
     *    ftc_cmap_node_compare
     *
     * =====================================================================
     */
    public static int ftc_cmap_node_compare(Object ... args) {
      Log.w(TAG, "ftc_cmap_node_compare not yet implemented");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_cmap_node_remove_faceid
     *
     * =====================================================================
     */
    public static int ftc_cmap_node_remove_faceid(Object ... args) {
      Log.w(TAG, "ftc_cmap_node_remove_faceid not yet implemented");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_cmap_node_free
     *
     * =====================================================================
     */
    public static int ftc_cmap_node_free(Object ... args) {
      Log.w(TAG, "ftc_cmap_node_free not yet implemented");
      int error = 0;

      return error;
    }

}

Added ftcache/FTCCMapNodeRec.java.























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCCMapNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCCMapNodeRec extends FTCNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCMapNodeRec";

    public final static int FTC_CMAP_INDICES_MAX = 128;
    public final static int FTC_CMAP_UNKNOWN = ~0;

    public Object face_id = null;
    public int cmap_index = 0;
    public int first = 0;
    public int indices[] = null;

    /* ==================== FTCCMapNodeRec ================================== */
    public FTCCMapNodeRec() {
      oid++;
      id = oid;
      
      indices =  new int[FTC_CMAP_INDICES_MAX];
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCCMapQueryRec.java.















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCCMapQueryRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCCMapQueryRec extends FTCGQueryRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCMapQueryRec";

    public final static int FTC_CMAP_INDICES_MAX = 128;

    public Object face_id = null;
    public int cmap_index = 0;
    public int char_code = 0;

    /* ==================== FTCCMapQueryRec ================================== */
    public FTCCMapQueryRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCCacheClassRec.java.





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCCacheClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCCacheClassRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCacheClassRec";

    public final static int FTC_CACHE_CLASS_UNKNONW_TYPE = 0;
    public final static int FTC_CACHE_CLASS_TYPE_FTCBasicICacheClass = 1;
    public final static int FTC_CACHE_CLASS_TYPE_FTCBasicSCacheClass = 2;
    public final static int FTC_CACHE_CLASS_TYPE_FTCCMapCacheClass = 3;

    public int node_type = FTCMruListClassRec.NODE_TYPE_FTC_GNODE_REC;
    public ftbase.FTInstanceMethod node_new = null;
    public ftbase.FTInstanceMethod node_weight = null;
    public ftbase.FTInstanceMethod node_compare = null;
    public ftbase.FTInstanceMethod node_remove_faceid = null;
    public ftbase.FTInstanceMethod node_free = null;

    public int cache_class_type = FTC_CACHE_CLASS_UNKNONW_TYPE;
    public ftbase.FTInstanceMethod cache_init = null;
    public ftbase.FTInstanceMethod cache_done = null;

    /* ==================== FTCCacheClassRec ================================== */
    public FTCCacheClassRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
    
    /* ==================== copy ===================================== */
    public void copy(FTCCacheClassRec from) {
      node_type = from.node_type;
      node_new = from.node_new;
      node_weight = from.node_weight;
      node_compare = from.node_compare;
      node_remove_faceid = from.node_remove_faceid;
      node_free = from.node_free;

      cache_class_type = from.cache_class_type;
      cache_init = from.cache_init;
      cache_done = from.cache_done;
    } 
}

Added ftcache/FTCCacheFuncs.java.







































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;

  /* ===================================================================== */
  /*    FTCCacheFuncs                                                      */
  /*                                                                       */
  /* ===================================================================== */

public class FTCCacheFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCacheFuncs";
    
    /* ==================== FTCCacheFuncs ================================== */
    public FTCCacheFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_gcache_init
     *
     * =====================================================================
     */
    public static int ftc_gcache_init(Object ... args) {
      FTCGCacheRec cache = (FTCGCacheRec)args[0];
      int error = 0;

Debug(0, DBG_CACHE, TAG, "FTCCacheFuncs  ftc_gcache_init: ");
      error = FTCCacheRec.FTCCacheInit(cache);
      if (error == 0) {
        FTCGCacheClassRec clazz = (FTCGCacheClassRec)cache.org_class;
Debug(0, DBG_CACHE, TAG, "ftc_gcache_init2: "+clazz.family_class.node_init+"!");
        FTCMruListRec.FTCMruListInit(cache.families, (FTCMruListClassRec)clazz.family_class,
          0  /* no maximum here! */, cache);
      }
      return error;
    }

    /* =====================================================================
     *    ftc_gcache_done
     *
     * =====================================================================
     */
    public static int ftc_gcache_done(Object ... args) {
      Log.w(TAG, "FTCCacheFuncs ftc_gcache_done not yet implemented");

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_basic_family_compare
     *
     * =====================================================================
     */
    public static boolean ftc_basic_family_compare(Object ... args) {
Debug(0, DBG_CACHE, TAG, "FTCCacheFuncs ftc_basic_family_compare");
      FTCMruNodeRec ftcmrunode = (FTCMruNodeRec)args[0];
      Object ftcquery = (Object)args[1];
      FTCBasicFamilyRec family = (FTCBasicFamilyRec)ftcmrunode;
      FTCBasicQueryRec query = (FTCBasicQueryRec)ftcquery;

      return FTC_SCALER_COMPARE(family.attrs.scaler, query.attrs.scaler);
    }

    /* =====================================================================
     *    ftc_basic_family_init
     *
     * =====================================================================
     */
    public static int ftc_basic_family_init(Object ... args) {
        ftbase.FTReference<Object> ftcfamily_ref = (ftbase.FTReference<Object>)args[0];
        Object ftcquery = args[1];
        Object ftccache = args[2];
        FTCMruNodeRec mru_node = (FTCMruNodeRec)ftcfamily_ref.Get();
        FTCBasicFamilyRec family = (FTCBasicFamilyRec)mru_node;
        FTCBasicQueryRec query = (FTCBasicQueryRec)ftcquery;
        FTCGCacheRec cache = (FTCGCacheRec)ftccache;

Debug(0, DBG_CACHE, TAG, "FTCCacheFuncs ftc_basic_family_init: "+ftccache);

        int error = 0;
        FTCFamilyInit(family, cache);
        family.attrs = query.attrs;
        ftcfamily_ref.Set(family);
        return error;
    }

    /* =====================================================================
     *    ftc_basic_family_get_count
     *
     * =====================================================================
     */
    public static int ftc_basic_family_get_count(Object ... args) {
Debug(0, DBG_CACHE, TAG, "FTCCacheFuncs ftc_basic_family_get_count");
      FTCFamilyRec ftcfamily = (FTCFamilyRec)args[0];
      FTCManagerRec manager = (FTCManagerRec)args[1];
      FTCBasicFamilyRec family = (FTCBasicFamilyRec)ftcfamily;
      int error = 0;
      ftbase.FTFaceRec face = null;
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = new ftbase.FTReference<ftbase.FTFaceRec>();
      int result = 0;

      face_ref.Set(face);
      error = FTCManagerRec.FTCManagerLookupFace(manager, (Object)family.attrs.scaler.face_id, face_ref);
      face = face_ref.Get();
      if (error != 0 || face_ref == null) {
        return result;
      }
//      if ((long)face.num_glyphs > FT_UINT_MAX || 0 > face.num_glyphs) {
//        FT_TRACE1(( "ftc_basic_family_get_count: too large number of glyphs " ));
//        FT_TRACE1(( "in this face, truncated\n", face.num_glyphs ));
//      }
      if (error == 0) {
        result = face.num_glyphs;
      }
      return result;
    }

    /* =====================================================================
     *    ftc_basic_family_load_bitmap
     *
     * =====================================================================
     */
    public static int ftc_basic_family_load_bitmap(Object ... args) {
Debug(0, DBG_CACHE, TAG, "ftc_basic_family_load_bitmap");
      FTCFamilyRec ftcfamily = (FTCFamilyRec)args[0];
      int gindex = (int)args[1];
      FTCManagerRec manager = (FTCManagerRec)args[2];
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = (ftbase.FTReference<ftbase.FTFaceRec>)args[3];
      ftbase.FTFaceRec face = face_ref.Get();
      FTCBasicFamilyRec family = (FTCBasicFamilyRec)ftcfamily;
      ftbase.FTSizeRec size = null;
      ftbase.FTReference<ftbase.FTSizeRec> size_ref = new ftbase.FTReference<ftbase.FTSizeRec>();
      int error = 0;

      /* we will now load the glyph image */
      ftbase.FTReference<FTCScalerRec> scaler_ref = new ftbase.FTReference<FTCScalerRec>();
      scaler_ref.Set(family.attrs.scaler);
      size_ref.Set(size);
      error = FTCManagerRec.FTCManagerLookupSize(manager, scaler_ref, size_ref);
      size = size_ref.Get();
      family.attrs.scaler = scaler_ref.Get();
      if (error == 0) {
        face = size.face;
        face_ref.Set(face);
        error = ftbase.FTGlyphLoaderRec.FTLoadGlyph(face_ref, gindex, (int)(family.attrs.load_flags | FTGlyphLoaderFlags.FT_LOAD_RENDER));
        face = face_ref.Get();
        if (error == 0) {
          face_ref.Set(face);
        }
      }
      return error;
    }

    /* =====================================================================
     *    ftc_basic_family_load_glyph
     *
     * =====================================================================
     */
    public static int ftc_basic_family_load_glyph(Object ... args) {
Debug(0, DBG_CACHE, TAG, "ftc_basic_family_load_glyph");
      FTCFamilyRec ftcfamily = (FTCFamilyRec)args[0];
      int gindex = (int)args[1];
      FTCManagerRec manager = (FTCManagerRec)args[2];
      // FIXME !!!
      FTCCacheRec cache = (FTCCacheRec)manager.caches[0];
      ftbase.FTReference<ftbase.FTGlyphRec> glyph_ref = (ftbase.FTReference<ftbase.FTGlyphRec>)args[3];
      ftbase.FTGlyphRec gylph = glyph_ref.Get();
      FTCBasicFamilyRec family = (FTCBasicFamilyRec)ftcfamily;
      FTCScalerRec scaler = family.attrs.scaler;
      ftbase.FTFaceRec face = null;
      ftbase.FTSizeRec size = null;
      ftbase.FTReference<ftbase.FTSizeRec> size_ref = new ftbase.FTReference<ftbase.FTSizeRec>();
      int error = 0;

      /* we will now load the glyph image */
      ftbase.FTReference<FTCScalerRec> scaler_ref = new ftbase.FTReference<FTCScalerRec>();
      size_ref.Set(size);
      scaler_ref.Set(scaler);
      error = FTCManagerRec.FTCManagerLookupSize(cache.manager, scaler_ref, size_ref);
      size = size_ref.Get();
      scaler = scaler_ref.Get();
      if (error == 0) {
        ftbase.FTReference<ftbase.FTFaceRec> face_ref = new ftbase.FTReference<ftbase.FTFaceRec>();
        face = size.face;
        face_ref.Set(face);
        error = ftbase.FTGlyphLoaderRec.FTLoadGlyph(face_ref, gindex, family.attrs.load_flags);
        face = face_ref.Get();
        if (error == 0) {
          if (face.glyph.format == FT_GLYPH_FORMAT_BITMAP  ||
              face.glyph.format == FT_GLYPH_FORMAT_OUTLINE) {
            /* ok, copy it */
            ftbase.FTGlyphRec glyph = null;
            ftbase.FTReference<ftbase.FTGlyphSlotRec> glyph_slot_ref = new ftbase.FTReference<ftbase.FTGlyphSlotRec>();

            glyph_slot_ref.Set(face.glyph);
            error = ftbase.FTGlyphLoaderRec.FTGetGlyph(glyph_slot_ref, glyph_ref);
            face.glyph = glyph_slot_ref.Get();
            glyph = glyph_ref.Get();
            if (error == 0) {
              glyph_ref.Set(glyph);
              return error;
            }
          } else {
            error = ftbase.FTError.GLYPH_INVALID_ARGUMENT;
	  }
        }
      }
      return error;
    }

    /* =====================================================================
     * FTCFamilyInit
     *
     * =====================================================================
     */
    public static void FTCFamilyInit(FTCFamilyRec family, Object cache_obj) {
      FTCGCacheRec cache = (FTCGCacheRec)cache_obj;
      FTCGCacheClassRec clazz = (FTCGCacheClassRec)cache.clazz;
Debug(0, DBG_CACHE, TAG, "FTCFamilyInit");
      family.clazz = clazz.family_class;
      family.num_nodes = 0;
      family.cache = (FTCCacheRec)cache;
    }

    /* =====================================================================
     * FTC_SCALER_COMPARE
     *
     * =====================================================================
     */
    public static boolean FTC_SCALER_COMPARE(FTCScalerRec scaler1, FTCScalerRec scaler2) {
Debug(0, DBG_CACHE, TAG, "FTC_SCALER_COMPARE");
      return ((scaler1.face_id == scaler2.face_id) &&
      (scaler1.width == scaler2.width) &&
      (scaler1.height == scaler2.height) &&
      (scaler1.pixel != 0) == (scaler2.pixel != 0) &&
      (scaler1.pixel != 0 ||
       (scaler1.x_res == scaler2.x_res && scaler1.y_res == scaler2.y_res)));
    }

}

Added ftcache/FTCCacheRec.java.



































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;
  /* ===================================================================== */
  /*    FTCCacheRec                                                        */
  /*                                                                       */
  /* each cache really implements a dynamic hash table to manage its nodes */
  /* ===================================================================== */

public class FTCCacheRec extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCCacheRec";

    public static int cache_debug = 0;

    public final static int FTC_HASH_INITIAL_SIZE = 8;
    public final static int FTC_HASH_MIN_LOAD = 1;
    public final static int FTC_HASH_MAX_LOAD = 2;
    public final static int FTC_HASH_SUB_LOAD = (FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD);

    public int p = 0;
    public int mask = 0;
    public long slack = 0L;         
    public FTCNodeRec[] buckets = null;
    public FTCCacheClassRec clazz = null;     /* local copy, for speed  */
    public FTCManagerRec manager = null;
    public int index = 0;                     /* in manager's table     */
    public FTCCacheClassRec org_class = null; /* original class pointer */

    /* ==================== FTCCacheRec ================================== */
    public FTCCacheRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      str.append(super.toString());
      str.append("    p: "+p+"\n");
      str.append("    mask: "+mask+"\n");
      str.append("    slack: "+slack+"\n");
      str.append("    clazz: "+clazz.toDebugString()+"\n");
      str.append("    manager: "+manager.toDebugString()+"\n");
      str.append("    index: "+index+"\n");
      str.append("    org_class: "+org_class.toDebugString()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTCCacheInit
     * =====================================================================
     */
    public static int FTCCacheInit(FTCCacheRec cache) {
      return ftc_cache_init(cache);
    }

   /* =====================================================================
    * FTCCacheLookup
    * =====================================================================
    */
   public static int FTCCacheLookup(FTCCacheRec cache, Object hash, Object query, ftbase.FTReference<FTCNodeRec> node_ref) {
     int error = ftbase.FTError.INTERP_ERR_OK;
     FTCNodeRec bucket;
     FTCNodeRec pnode;
     FTCNodeRec node = node_ref.Get();
     int pnodeIdx= -1;
     boolean list_changed = false;
     boolean isLinkNode = false;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCCacheLookup");
}
     ftbase.FTInstanceMethod compare = cache.clazz.node_compare;

     if (cache == null || node_ref == null) {
       return ftbase.FTError.GLYPH_INVALID_ARGUMENT;
     }
     /* Go to the `top' node of the list sharing same masked hash */
     pnodeIdx = FTCMruFuncs.ftc_get_top_node_for_hash(cache, hash);
     pnode = cache.buckets[pnodeIdx];
     bucket = pnode;
     
     /* Lookup a node with exactly same hash and queried properties.  */
     /* NOTE: _nodcomp() may change the linked list to reduce memory. */
     for (;;) {
       if (isLinkNode) {
         node = pnode.link; 
       } else {
         node = pnode;
       }
       if (node == null) {
         return FTCCacheNewNode(cache, hash, query, node_ref);
       }
       ftbase.FTReference<Boolean> flag_ref = new ftbase.FTReference<Boolean>();
       flag_ref.Set(list_changed);
       if (node.hash == (int)hash &&
            (boolean)compare.callClassMethod(node, query, cache, flag_ref)) {
         list_changed = flag_ref.Get();
         break;
       }
       isLinkNode = true;
       pnode = node;
     }
     if (list_changed) {
       /* Update bucket by modified linked list */
       pnodeIdx = FTCMruFuncs.ftc_get_top_node_for_hash( cache, hash );
       pnode = cache.buckets[pnodeIdx];
       bucket = pnode;
       isLinkNode = false;
       /* Update pnode by modified linked list */
       while (pnode != node) {
         if ((isLinkNode ? pnode.link : pnode) == null) {
           ftbase.FTTrace.Trace(7, TAG, "FTC_Cache_Lookup: oops!!!  node missing");
           return FTCCacheNewNode(cache, hash, query, node_ref);
         } else {
           isLinkNode = true;
           pnode = pnode.link;
         }
       }
     }
     /* Reorder the list to move the found node to the `top' */
     if (node != bucket) {
       isLinkNode = true;
       pnode = node;
       node.link = bucket;
       bucket = node;
     }
     /* move to head of MRU list */
     {
       FTCManagerRec manager = cache.manager;

       if (node != manager.nodes_list) {
         FTCMruFuncs.ftc_node_mru_up(node, manager);
       }
     }
     node_ref.Set(node);
     return error;
   }

   /* =====================================================================
    * FTCCacheNewNode
    * =====================================================================
    */
   public static int FTCCacheNewNode(FTCCacheRec cache, Object hash, Object query, ftbase.FTReference<FTCNodeRec> node_ref) {
     int error = ftbase.FTError.INTERP_ERR_OK;
     FTCNodeRec node;
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCCacheNewNode");
}
     /*
      * We use the FTC_CACHE_TRYLOOP macros to support out-of-memory
      * errors (OOM) correctly, i.e., by flushing the cache progressively
      * in order to make more room.
      */

// FIXME to be implemented later !!
//      FTC_CACHE_TRYLOOP( cache )
     {
       ftbase.FTReference<FTCCacheRec> cache_ref = new ftbase.FTReference<FTCCacheRec>();
       cache_ref.Set(cache);
       error = (int)cache.clazz.node_new.callClassMethod(node_ref, query, cache_ref);
       node = node_ref.Get();
       cache = cache_ref.Get();
     }
//      FTC_CACHE_TRYLOOP_END( NULL );
     if (error != 0) {
       node = null;
     } else {
      /* don't assume that the cache has the same number of buckets, since
       * our allocation request might have triggered global cache flushing
       */
       node_ref.Set(node);
       ftc_cache_add(cache, (Object)hash, node_ref);
     }
     node_ref.Set(node);
     return error;
   }

    /* =====================================================================
     * ftc_cache_init
     * =====================================================================
     */
    public static int ftc_cache_init(Object ... args) {
      FTCCacheRec cache = (FTCCacheRec)args[0];
      int error = 0;

      cache.p = 0;
      cache.mask = FTC_HASH_INITIAL_SIZE - 1;
      cache.slack = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD;
      cache.buckets = new FTCNodeRec[FTC_HASH_INITIAL_SIZE * 2];
      return error;
    }

    /* =====================================================================
     *    ftc_cache_done
     *
     * =====================================================================
     */
    public static int ftc_cache_done(Object ... args) {
      Log.w(TAG, "ftc_cache_done not yet implemented");
//      Object obj = args[0];

      int error = 0;

      return error;
    }

    /* =====================================================================
     * ftc_cache_add
     * =====================================================================
     */
    public static void ftc_cache_add(FTCCacheRec cache, Object hash, ftbase.FTReference<FTCNodeRec> node_ref) {
      FTCNodeRec node = node_ref.Get();    	
      node.hash = (int)hash;
      node.cache_index = (short)cache.index;
      node.ref_count = 0;

      ftc_node_hash_link(node, cache);
      FTCMruFuncs.ftc_node_mru_link(node, cache.manager);
      {
        FTCManagerRec manager = cache.manager;

        int val = (int)(cache.clazz.node_weight.callClassMethod(node, cache));
        manager.cur_weight += val;

        if (manager.cur_weight >= manager.max_weight) {
          node.ref_count++;
          FTCManagerRec.FTCManagerCompress(manager);
          node.ref_count--;
        }
      }
    }

    /* =====================================================================
     * ftc_node_hash_link
     * =====================================================================
     */
    public static void ftc_node_hash_link(FTCNodeRec node, FTCCacheRec cache) {
      int idx = FTCMruFuncs.ftc_get_top_node_for_hash(cache, node.hash);

      node.link = cache.buckets[idx];
      cache.buckets[idx] = node;
      cache.slack--;
      FTCMruFuncs.ftc_cache_resize(cache);
    }

}

Added ftcache/FTCFaceListClass.java.

















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCFaceListClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCFaceListClass extends FTCMruListClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCFaceListClass";

    /* ==================== FTCFaceListClass ================================== */
    public FTCFaceListClass() {
      super("FTCMruListRec");
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCFaceListFuncs";
      this.node_type = NODE_TYPE_FTC_FACE_NODE_REC;
      this.node_compare = new ftbase.FTInstanceMethod(class_name, "ftc_face_node_compare", 1);
      this.node_init    = new ftbase.FTInstanceMethod(class_name, "ftc_face_node_init", 1);
      this.node_reset   = null;
      this.node_done    = new ftbase.FTInstanceMethod(class_name, "ftc_face_node_done", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCFaceListFuncs.java.































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

import android.util.Log;

  /* ===================================================================== */
  /*    FTCFaceListFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCFaceListFuncs extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCFaceListFuncs";
    
    /* ==================== FTCFaceListFuncs ================================== */
    public FTCFaceListFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_face_node_compare
     *
     * =====================================================================
     */
    public static boolean ftc_face_node_compare(Object ... args) {
Debug(0, DBG_CACHE, TAG, "ftc_face_node_compare");
      FTCMruNodeRec ftcnode = (FTCMruNodeRec)args[0];
      Object ftcface_id = args[1];
      FTCFaceNodeRec node = (FTCFaceNodeRec)ftcnode;
      Object face_id = ftcface_id;

      return node.face_id == face_id;
    }

    /* =====================================================================
     *    ftc_face_node_init
     *
     * =====================================================================
     */
    public static int ftc_face_node_init(Object ... args) {
Debug(0, DBG_CACHE, TAG, "ftc_face_node_init"+args[0]+"!"+args[1]+"!");
      ftbase.FTReference<Object> obj_ref = (ftbase.FTReference<Object>)args[0];
      FTCMruNodeRec ftcnode = (FTCMruNodeRec)obj_ref.Get();
      Object ftcface_id = args[1];
      Object ftcmanager = args[2];
      int error = 0;
      FTCFaceNodeRec node = (FTCFaceNodeRec)ftcnode;
      Object face_id = ftcface_id;
      FTCManagerRec manager = (FTCManagerRec)ftcmanager;

      node.face_id = face_id;
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = new ftbase.FTReference<ftbase.FTFaceRec>();
      face_ref.Set(node.face);
      error = (int)manager.request_face.callClassMethod(face_id,
              manager.library, manager.request_data, face_ref);
      node.face = face_ref.Get();
      if (error != 0) {
        /* destroy initial size object; it will be re-created later */
        if (node.face.size != null) {
//          FTDoneSize(node.face.size);
        }
      }
      obj_ref.Set(node);
      return error;
    }

    /* =====================================================================
     *    ftc_face_node_done
     *
     * =====================================================================
     */
    public static int ftc_face_node_done(Object ... args) {
      Log.w(TAG, "ftc_face_node_done not yet implemented");

      int error = 0;

      return error;
    }

}

Added ftcache/FTCFaceNodeRec.java.































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCFaceNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCFaceNodeRec extends FTCMruNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCFaceNodeRec";

    public Object face_id = null;
    public ftbase.FTFaceRec face = null;

    /* ==================== FTCFaceNodeRec ================================== */
    public FTCFaceNodeRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== FTCFaceNodeRec ================================== */
    public FTCFaceNodeRec(FTCMruNodeRec node) {
      oid++;
      id = oid;
      
      this.next = node.next;
      this.prev = node.prev;;
      face = new ftbase.FTFaceRec("FTCFaceNodeRec");
      face_id = face;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCFamilyClassRec.java.











































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCFamiliyClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCFamilyClassRec extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCFamilyClassRec";

    public long family_size = 0L;
    public ftbase.FTInstanceMethod family_get_count = null;
    public ftbase.FTInstanceMethod family_load_glyph = null;

    /* ==================== FTCFamiliyClassRec ================================== */
    public FTCFamilyClassRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

}

Added ftcache/FTCFamilyRec.java.







































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCFamilyRec                                                       */
  /*                                                                       */
  /*  We can group glyphs into `families'.  Each family correspond to a    */
  /*  given face ID, character size, transform, etc.                       */
  /*                                                                       */ 
  /*  Families are implemented as MRU list nodes.  They are                */
  /*  reference-counted.                                                   */
  /* ===================================================================== */

public class FTCFamilyRec extends FTCMruNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCFamilyRec";

    public int num_nodes = 0; /* current number of nodes in this family */
    public FTCCacheRec cache = null;
    public FTCMruListClassRec clazz = null;

    /* ==================== FTCFamilyRec ================================== */
    public FTCFamilyRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== FTCFamilyRec ================================== */
    public FTCFamilyRec(FTCMruNodeRec mru_node) {
      super();
      oid++;
      id = oid;
      this.next = mru_node.next;
      this.prev = mru_node.prev;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCGCacheClassRec.java.







































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCGCacheClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCGCacheClassRec extends FTCCacheClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCGCacheClassRec";

    public FTCMruListClassRec family_class = null;

    /* ==================== FTCGCacheClassRec ================================== */
    public FTCGCacheClassRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      str.append("    node_new: "+node_new+"\n");
      str.append("    node_weight: "+node_weight+"\n");
      str.append("    node_compare: "+node_compare+"\n");
      str.append("    node_remove_faceid: "+node_remove_faceid+"\n");
      str.append("    node_free: "+node_free+"\n");
      str.append("    cache_class_type: "+cache_class_type+"\n");
      str.append("    cache_init: "+cache_init+"\n");
      str.append("    cache_done: "+cache_done+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTCGCacheNew
     * =====================================================================
     */
    public static int FTCGCacheNew(FTCManagerRec manager, FTCGCacheClassRec clazz, ftbase.FTReference<FTCGCacheRec> cache_ref) {
      return FTCManagerRec.FTCManagerRegisterCache(manager, clazz, cache_ref);
    }

}

Added ftcache/FTCGCacheRec.java.































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCGCacheRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCGCacheRec extends FTCCacheRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCGCacheRec";

    public FTCMruListRec families = null;

    /* ==================== FTCGCacheRec ================================== */
    public FTCGCacheRec() {
      oid++;
      id = oid;
      families = new FTCMruListRec("families1");
    }
    
    /* ==================== FTCGCacheRec ================================== */
    public FTCGCacheRec(FTCCacheRec cache_rec, FTCMruListRec family) {
      oid++;
      id = oid;
      p = cache_rec.p;
      mask = cache_rec.mask;
      slack = cache_rec.slack;         
      buckets = cache_rec.buckets;
      clazz = cache_rec.clazz;
      manager = cache_rec.manager;
      index = cache_rec.index;
      org_class = cache_rec.org_class;

      families = family;
    }

    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTCGCacheLookup
     * =====================================================================
     */
    public static int FTCGCacheLookup(FTCGCacheRec cache, int hash, int gindex,
           FTCGQueryRec query, ftbase.FTReference<FTCNodeRec> node_ref) {
      int error = 0;

Debug(0, DBG_CACHE, TAG, "FTCGCacheLookup");
      query.gindex = gindex;
      ftbase.FTReference<Object> family_ref = new ftbase.FTReference<Object>();
Debug(0, DBG_CACHE, TAG, "FTCGCacheLookup2: "+cache.families+"!"+cache.families.data);
      family_ref.Set(query.family);
      error = FTCMruListRec.FTCMruListLookup(cache.families, (Object)query, family_ref);
      query.family = (FTCFamilyRec)family_ref.Get();
      if (error == 0) {
        /* prevent the family from being destroyed too early when an        */
        /* out-of-memory condition occurs during glyph node initialization. */
        query.family.num_nodes++;
        error = FTCCacheRec.FTCCacheLookup((FTCCacheRec)cache, hash, query, node_ref);
        if (--query.family.num_nodes == 0) {
//          FTC_FAMILY_FREE( family, cache );
        }
      }
      return error;
    }

}

Added ftcache/FTCGNodeRec.java.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCGNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCGNodeRec extends FTCNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCGNodeRec";

    public FTCFamilyRec family = null;
    public int gindex = 0;

    /* ==================== FTCGNodeRec ================================== */
    public FTCGNodeRec() {
      oid++;
      id = oid;
      
      family = new FTCFamilyRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCGQueryRec.java.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftcache;

  /* ===================================================================== */
  /*    FTCGQueryRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCGQueryRec extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCGQueryRec";

    public int gindex = 0;
    public FTCFamilyRec family = null;

    /* ==================== FTCGQueryRec ================================== */
    public FTCGQueryRec() {
      oid++;
      id = oid;

     family = new FTCFamilyRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCHashFuncs.java.







































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// ----------------------------------------------------------------
// FTCHashFuncs.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCHashFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCHashFuncs extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCHashFuncs";

    public final static int FTC_CMAP_INDICES_MAX = 128;

    /* ==================== FTCHashFuncs ================================== */
    public FTCHashFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * _FTC_FACE_ID_HASH
     * =====================================================================
     */
    public static int _FTC_FACE_ID_HASH(Object obj_i) {
      int i = obj_i.hashCode();
      return ((i >> 3) ^ (i << 7));
    } 

    /* =====================================================================
     * FTC_SCALER_HASH
     * =====================================================================
     */
    public static int FTC_SCALER_HASH(FTCScalerRec q) {
      int val1 = _FTC_FACE_ID_HASH(q);
      int val2 = q.face_id.hashCode();
      return val1 + val2 + q.width + q.height * 7 + 
	      (q.pixel != 0 ? 0 : q.x_res * 33 ^ q.y_res * 61);
    }

    /* =====================================================================
     * FTC_CMAP_HASH
     * =====================================================================
     */
    public static int FTC_CMAP_HASH(Object faceid, int index, int charcode) {
      return _FTC_FACE_ID_HASH(faceid) + 211 * index +
	      (charcode / FTC_CMAP_INDICES_MAX);
    }

    /* =====================================================================
     * FTC_BASIC_ATTR_HASH
     * =====================================================================
     */
    public static int FTC_BASIC_ATTR_HASH(FTCBasicAttrRec a) { 
      return FTC_SCALER_HASH(a.scaler) + 31*a.load_flags;
    }
 
}

Added ftcache/FTCIFamilyClassRec.java.































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// ----------------------------------------------------------------
// FTCIFamilyClassRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCIFamilyClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCIFamilyClassRec extends FTCMruListClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCIFamilyClassRec";

    public TTInstanceMethod family_load_glyph = null;

    /* ==================== FTCIFamilyClassRec ================================== */
    public FTCIFamilyClassRec(String initStr) {
      super(initStr);
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCINodeRec.java.







































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// ----------------------------------------------------------------
// FTCINodeRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCINodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCINodeRec extends FTCGNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCINodeRec";

    public FTCGNodeRec gnode = null;
    public FTGlyphRec glyph = null;

    /* ==================== FTCINodeRec ================================== */
    public FTCINodeRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * =====================================================================
     */

}

Added ftcache/FTCManagerRec.java.





























































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// ----------------------------------------------------------------
// FTCManagerRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

import android.util.Log;
import org.apwtcl.gles20.batikfont.ftraster.FT_Error;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCManagerRec                                                      */
  /*                                                                       */
  /* <Description>                                                         */
  /*    This object corresponds to one instance of the cache-subsystem.    */
  /*    It is used to cache one or more @FT_Face objects, along with       */
  /*    corresponding @FT_Size objects.                                    */
  /*                                                                       */
  /*    The manager intentionally limits the total number of opened        */
  /*    @FT_Face and @FT_Size objects to control memory usage.  See the    */
  /*    `max_faces' and `max_sizes' parameters of @FTC_Manager_New.        */
  /*                                                                       */
  /*    The manager is also used to cache `nodes' of various types while   */
  /*    limiting their total memory usage.                                 */
  /*                                                                       */
  /*    All limitations are enforced by keeping lists of managed objects   */
  /*    in most-recently-used order, and flushing old nodes to make room   */
  /*    for new ones.                                                      */
  /*                                                                       */
  /* ===================================================================== */

public class FTCManagerRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCManagerRec";

    private final static int FTC_MAX_FACES_DEFAULT = 2;
    private final static int FTC_MAX_SIZES_DEFAULT = 4;
    private final static int FTC_MAX_CACHES = 16;

    public FTLibraryRec library = null;
    public FTCNodeRec nodes_list = null;
    public long max_weight = 0L;
    public long cur_weight = 0L;
    public int num_nodes = 0;
    public FTCCacheRec[] caches = new FTCCacheRec[FTC_MAX_CACHES];
    public int num_caches = 0;
    public FTCMruListRec faces = null;
    public FTCMruListRec sizes = null;
    public Object request_data = null;
    public TTInstanceMethod request_face = null;

    /* ==================== FTCManagerRec ================================== */
    public FTCManagerRec() {
      oid++;
      id = oid;
      faces = new FTCMruListRec("manager.faces");
      sizes = new FTCMruListRec("manager.sizes");
      for (int i = 0; i < FTC_MAX_CACHES; i++) {
        caches[i] = new FTCCacheRec();
      }
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

    /* =====================================================================
     * FTCManagerNew
     * =====================================================================
     */
    public static int FTCManagerNew(FTLibraryRec library, int max_faces, int max_sizes,
            TTInstanceMethod requester, Object req_data, FTReference<FTCManagerRec> manager_ref) {
      int error = 0;
      FTCManagerRec manager = null;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerNew");
}
      if (library  == null) {
        error= FT_Error.GLYPH_INVALID_LIBRARY_HANDLE;
        return error;
      }
      manager = new FTCManagerRec();
      if (max_faces == 0) {
        max_faces = FTC_MAX_FACES_DEFAULT;
      }
      if (max_sizes == 0) {
        max_sizes = FTC_MAX_SIZES_DEFAULT;
      }
      manager.library = library;
      manager.request_face = requester;
      manager.request_data = req_data;
if (FTCCacheRec.cache_debug > 2) {
System.out.println("call FTC_MruList_Init faces FTCFaceListClass");
}
      FTCMruListRec.FTCMruListInit(manager.faces, (FTCMruListClassRec)new FTCFaceListClass(), max_faces, manager);
if (FTCCacheRec.cache_debug > 2) {
System.out.println("call FTC_MruList_Init sizes FTCSizeListClass");
}
      FTCMruListRec.FTCMruListInit(manager.sizes, (FTCMruListClassRec)new FTCSizeListClass(), max_sizes, manager);
      manager_ref.Set(manager);
      return error;
    }
    
    /* =====================================================================
     * FTCSBitCacheNew
     * =====================================================================
     */
    public static int FTCSBitCacheNew(FTCManagerRec manager, FTReference<FTCGCacheRec> cache_ref) {
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCSBitCacheNew");
}
      return FTCGCacheClassRec.FTCGCacheNew(manager, new FTCBasicSCacheClass(), cache_ref);
    }
    
    /* =====================================================================
     * FTCCMapCacheNew
     * =====================================================================
     */
    public static int FTCCMapCacheNew(FTCManagerRec cache_manager, FTReference<FTCGCacheRec> cache_ref) {
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCCMapCacheNew");
}
      return FTCManagerRegisterCache(cache_manager, new FTCCMapCacheClass(), cache_ref);
    }
    
    /* =====================================================================
     * FTCImageCacheNew
     * =====================================================================
     */
    public static int FTCImageCacheNew(FTCManagerRec cache_manager, FTReference<FTCGCacheRec> cache_ref) {
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCImageCacheNew");
}
      return FTCGCacheClassRec.FTCGCacheNew(cache_manager, new FTCBasicICacheClass(), cache_ref);
    }
    
    /* =====================================================================
     * FTCManagerRegisterCache
     * =====================================================================
     */
    public static int FTCManagerRegisterCache(FTCManagerRec manager, FTCCacheClassRec clazz, FTReference<FTCGCacheRec> cache_ref) {
      int error = FT_Error.GLYPH_INVALID_ARGUMENT;
      FTCGCacheRec cache = null;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerRegisterCache");
}
      if (manager != null && clazz != null && cache_ref != null) {
        if (manager.num_caches >= FTC_MAX_CACHES) {
          error = FT_Error.GLYPH_TOO_MANY_CACHES;
          Log.e(TAG, "FTCManagerRegisterCache: too many registered caches");
          return error;
        }
        cache = new FTCGCacheRec();
        if (cache != null) {
          cache.manager = manager;
          switch (clazz.cache_class_type) {
          case FTCCacheClassRec.FTC_CACHE_CLASS_TYPE_FTCBasicICacheClass:
            cache.clazz = new FTCBasicICacheClass();
            cache.clazz.copy(clazz);
            break;
          case FTCCacheClassRec.FTC_CACHE_CLASS_TYPE_FTCBasicSCacheClass:
            cache.clazz = new FTCBasicSCacheClass();
            cache.clazz.copy(clazz);
            break;
          case FTCCacheClassRec.FTC_CACHE_CLASS_TYPE_FTCCMapCacheClass:
            cache.clazz = new FTCCMapCacheClass();
            cache.clazz.copy(clazz);
            break;
          default:
            error = FT_Error.GLYPH_BAD_CACHE_CLASS_TYPE;
            Log.e(TAG, "FTCManagerRegisterCache: bad cache_class_type");
            return error;            
          }
if (FTCCacheRec.cache_debug > 2) {
System.out.println("cache.class: "+clazz.toDebugString());
}
          cache.org_class = (FTCCacheClassRec)clazz;
          /* THIS IS VERY IMPORTANT!  IT WILL WRETCH THE MANAGER */
          /* IF IT IS NOT SET CORRECTLY                          */
          cache.index = manager.num_caches;
          error = (int)clazz.cache_init.callClassMethod(cache);
          if (error != 0) {
            clazz.cache_done.callClassMethod(cache);
            cache = null; // free allocated cache record
            return error;
          }
          manager.caches[manager.num_caches++] = cache;
        }
      }
      if (cache_ref != null) {
        cache_ref.Set(cache);
      }
      return error;
    }

    /* =====================================================================
     * FTCManagerLookupSize
     * =====================================================================
     */
    public static int FTCManagerLookupSize(FTCManagerRec manager, FTReference<FTCScalerRec> scaler_ref, FTReference<FTSizeRec> size_ref) {
      int error = 0;
      FTReference<Object> mru_ref = new FTReference<Object>();
      FTCScalerRec scaler = scaler_ref.Get();
      FTCMruNodeRec mrunode = null;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerLookupSize");
}
      if (size_ref == null) {
        return FT_Error.GLYPH_INVALID_ARGUMENT;
      }
      size_ref.Set(null);
      if (manager == null) {
        return FT_Error.GLYPH_INVALID_CACHE_HANDLE;
      }
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerLookupSize1b");
}
      error = FTCMruListRec.FTCMruListLookup(manager.sizes, (Object)scaler, mru_ref);
      mrunode = (FTCMruNodeRec)mru_ref.Get();
      if (error == 0) {
        FTCSizeNodeRec size_node = (FTCSizeNodeRec)mrunode;
        size_node.scaler = scaler;
        size_ref.Set(size_node.size);
      }
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerLookupSize2");
}
      scaler_ref.Set(scaler);
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerLookupSize3");
}
      return error;
    }

    /* =====================================================================
     * FTCManagerLookupFace
     * =====================================================================
     */
    public static int FTCManagerLookupFace(FTCManagerRec manager, Object face_id, FTReference<FTFaceRec> face_ref) {
      int error = 0;

      FTReference<Object> mru_ref = new FTReference<Object>();

if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCManagerLookupFace");
}
      if (face_ref == null) {
        return FT_Error.GLYPH_INVALID_ARGUMENT;
      }
      face_ref.Set(null);
      if (manager == null) {
        return FT_Error.GLYPH_INVALID_CACHE_HANDLE;
      }
      error = FTCMruListRec.FTCMruListLookup(manager.faces, (Object)face_id, mru_ref);
      FTCFaceNodeRec face_node = (FTCFaceNodeRec)mru_ref.Get();
      if (error == 0) {
if (FTCCacheRec.cache_debug > 2) {
System.out.println("face_node.face: "+face_node+"+"+face_node.face+"+"+face_node.face.driver);
}
        face_ref.Set(face_node.face);
      }
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTC_Manager_LookupFace end "+face_node+"+"+face_node.face+"+"+face_node.face.driver);
}
      return error;
    }

    /* =====================================================================
     * FTCManagerCompress
     * =====================================================================
     */
    public static void FTCManagerCompress(FTCManagerRec manager) {
      FTCMruNodeRec node;
      FTCNodeRec first;
      FTCMruNodeRec prev;

      if (manager == null) {
        return;
      }
      first = manager.nodes_list;

//      FTC_Manager_Check( manager );
      FT_Trace.Trace(7, TAG, String.format("compressing, weight = %d, max = %d, nodes = %d",
          manager.cur_weight, manager.max_weight, manager.num_nodes ));
      if (manager.cur_weight < manager.max_weight || first == null) {
        return;
      }
      /* go to last node -- it's a circular list */
      node = first.prev;
      do {

        prev = ( node == first ) ? null : node.prev;
        if (((FTCNodeRec)node).ref_count <= 0) {
          FTCMruFuncs.ftc_node_destroy((FTCNodeRec)node, manager);
        }
        node = prev;
      } while (node != null && manager.cur_weight > manager.max_weight);
    }

}

Added ftcache/FTCMapClassRec.java.







































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// ----------------------------------------------------------------
// FTCMapClassRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCMapClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCMapClassRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCMapClassRec";

    public final static int FT_CMAP_CLASS_UNKNONW_TYPE = -1;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap0Class = 0;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap2Class = 2;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap4Class = 4;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap6Class = 6;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap8Class = 8;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap10Class = 10;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap12Class = 12;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap13Class = 13;
    public final static int FT_CMAP_CLASS_TYPE_TTCMap14Class = 14;

    public int cmap_class_type = FT_CMAP_CLASS_UNKNONW_TYPE;
    public TTInstanceMethod init = null;
    public TTInstanceMethod done = null;
    public TTInstanceMethod char_index = null;
    public TTInstanceMethod char_next = null;

    public TTInstanceMethod char_var_index = null;
    public TTInstanceMethod char_var_default = null;
    public TTInstanceMethod variant_list = null;
    public TTInstanceMethod charvariant_list = null;
    public TTInstanceMethod variantchar_list = null;

    /* ==================== FTCMapClassRec ================================== */
    public FTCMapClassRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
    
}

Added ftcache/FTCMapRec.java.





















































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// ----------------------------------------------------------------
// FTCMapRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

import android.util.Log;
import org.apwtcl.gles20.batikfont.ftraster.*;

import ftbase.FTCharMapRec;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCMapRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCMapRec extends FTCharMapRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCMapRec";

    public FTCMapClassRec clazz = null;

    /* ==================== FTCMapRec ================================== */
    public FTCMapRec() {
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

    /* ==================== FTCMapNew ===================================== */
    public static int FTCMapNew(FTCMapClassRec clazz, byte[] init_data, int init_offset, FTCharMapRec charmap, FTReference<FTCMapRec> acmap) {
      int error = 0;
      FTFaceRec face;
      FTCMapRec cmap = null;
  
      if (clazz == null || charmap == null || charmap.face == null) {
        return FT_Error.GLYPH_INVALID_ARGUMENT;
      } 
      face = charmap.face;
      switch (clazz.cmap_class_type) {
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap0Class:
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap2Class:
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap6Class:
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap8Class:
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap10Class:
        cmap = (FTCMapRec)new TTCMapRec();
        break;
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap4Class:
        cmap = (FTCMapRec)new TTCMap4Rec();
        break;
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap12Class:
        cmap = (FTCMapRec)new TTCMap12Rec();
        break;
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap13Class:
        cmap = (FTCMapRec)new TTCMap13Rec();
        break;
      case FTCMapClassRec.FT_CMAP_CLASS_TYPE_TTCMap14Class:
        cmap = (FTCMapRec)new TTCMap14Rec();
        break;
      default:
        Log.e(TAG, String.format("funny TTCMapClassType: %d", clazz.cmap_class_type));
      }
      cmap.face = charmap.face;
      cmap.encoding = charmap.encoding;
      cmap.platform_id = charmap.platform_id;
      cmap.encoding_id = charmap.encoding_id;
      
      cmap.clazz = clazz;
      if (clazz.init != null) {
        error = (int)clazz.init.callClassMethod(cmap, init_data, init_offset);
        if (error != 0) {
//FIXME!!      ft_cmap_done_internal(cmap);
          cmap = null;
          if (acmap != null) {
            acmap.Set(cmap);
          }
          return error;
        }
        /* add it to our list of charmaps */
        face.charmaps = (FTCharMapRec[])FTUtil.FT_RENEW_ARRAY(face.charmaps, "charmaps", face.num_charmaps, face.num_charmaps + 1);
        face.charmaps[face.num_charmaps++] = (FTCharMapRec)cmap;
      }
      if (acmap != null) {
        acmap.Set(cmap);
      }
      return error;
    }
 
}

Added ftcache/FTCMruFuncs.java.











































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// ----------------------------------------------------------------
// FTCMruFuncs.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCMruFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCMruFuncs extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCMruFuncs";

    public static final int FTC_HASH_MIN_LOAD = 1;
    public static final int FTC_HASH_MAX_LOAD = 2;
    public static final int FTC_HASH_SUB_LOAD = FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD;
    public static final int FTC_HASH_INITIAL_SIZE = 8;

    /* ==================== FTCMruFuncs ================================== */
    public FTCMruFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * ftc_node_mru_link
     * =====================================================================
     */
    public static void ftc_node_mru_link(FTCNodeRec node, FTCManagerRec manager) {
      FTReference<FTCMruNodeRec> nodes_list_ref = new FTReference<FTCMruNodeRec>();
      nodes_list_ref.Set(manager.nodes_list);
      FTCMruNodeRec.FTCMruNodePrepend(nodes_list_ref, (FTCMruNodeRec)node);
      manager.nodes_list = (FTCNodeRec)nodes_list_ref.Get();
      manager.num_nodes++;
    }

    /* =====================================================================
     * ftc_node_mru_unlink
     * =====================================================================
     */
    public static void ftc_node_mru_unlink(FTCNodeRec node, FTCManagerRec manager) {
      FTCMruNodeRec.FTCMruNodeRemove(manager.nodes_list, (FTCMruNodeRec)node);
      manager.num_nodes--;
    }

    /* =====================================================================
     * ftc_node_mru_up
     * =====================================================================
     */
    /* move a node to the head of the manager's MRU list */
    static void ftc_node_mru_up(FTCNodeRec node, FTCManagerRec manager) {
      FTCMruNodeRec.FTCMruNodeUp(manager.nodes_list, (FTCMruNodeRec)node);
    }

    /* =====================================================================
     * ftc_get_top_node_for_hash
     * =====================================================================
     */
    /* get a top bucket for specified hash from cache,
     * body for FTC_NODE__TOP_FOR_HASH( cache, hash )
     */
    public static int ftc_get_top_node_for_hash(FTCCacheRec cache, Object hash) {
      int idx;

      idx = (int)((int)hash & cache.mask);
      if (idx < cache.p) {
        idx = (int)((int)hash & (2 * cache.mask + 1));
      }
      return idx;
    }


    /* =====================================================================
     * ftc_cache_resize
     * =====================================================================
     */
    public static void ftc_cache_resize(FTCCacheRec cache) {
      for (;;) {
        FTCNodeRec node;
        FTCNodeRec pnode;
        FTCNodeRec linkNode = null;
        int pnodeIdx;
        int linkIdx;
        int p = cache.p;
        int mask = cache.mask;
        int count = mask + p + 1;    /* number of buckets */

        /* do we need to shrink the buckets array? */
        if (cache.slack < 0) {
          FTCNodeRec new_list = null;

          /* try to expand the buckets array _before_ splitting
           * the bucket lists
           */
          if (p >= mask) {
            /* if we can't expand the array, leave immediately */
            Log.e(TAG, "FT_RENEW_ARRAY not yet implemented");
            return;
//            if (FT_RENEW_ARRAY(cache.buckets,
//                                 (mask + 1) * 2, (mask + 1) * 4)) {
//              break;
//            }
          }
          /* split a single bucket */
          pnode = cache.buckets[p];
	  linkIdx = p;
          for (;;) {
            node = pnode;
            if (node == null) {
              break;
            }
            if (((int)node.hash & (mask + 1)) != 0) {
              linkNode = pnode;
              pnode = node.link;
              node.link = new_list;
              new_list = node;
            } else {
              linkNode = pnode;
              pnode = node.link;
            }
          }
          cache.buckets[p + mask + 1] = new_list;
          cache.slack += FTC_HASH_MAX_LOAD;
          if (p >= mask) {
            cache.mask = 2 * mask + 1;
            cache.p    = 0;
          } else {
            cache.p = p + 1;
          }
        } else {
          /* do we need to expand the buckets array? */
          if (cache.slack > (long)count * FTC_HASH_SUB_LOAD) {
            int old_index = p + mask;
            FTCNodeRec pold;

            if (old_index + 1 <= FTC_HASH_INITIAL_SIZE) {
              break;
            }
            if (p == 0) {
              int error;

              /* if we can't shrink the array, leave immediately */
              Log.e(TAG, "FT_RENEW_ARRAY not yet implemented");
              return;
//              if (FT_RENEW_ARRAY(cache.buckets,
//                                 (mask + 1) * 2, mask + 1)) {
//                break;
//              }
//              cache.mask >>= 1;
//              p = cache.mask;
            } else {
              p--;
            }
            linkNode = null;
	    linkIdx = p;
            pnode = cache.buckets[p];
            while (pnode != null) {
              linkNode = pnode;
              pnode = pnode.link;
            }
            pold = cache.buckets[old_index];
            if (linkNode != null) {
              linkNode.link = pold;
            } else {
              cache.buckets[linkIdx] = pold;
            }
            pold = null;
            cache.slack -= FTC_HASH_MAX_LOAD;
            cache.p = p;
          } else {
            /* otherwise, the hash table is balanced */
            break;
          }
        }
      }
    }

    /* =====================================================================
     * ftc_node_hash_unlink
     * =====================================================================
     */
    /* remove a node from its cache's hash table */
    public static void ftc_node_hash_unlink(FTCNodeRec node0, FTCCacheRec cache) {
      int node0Idx = ftc_get_top_node_for_hash(cache, node0.hash);
      FTCNodeRec pnode = cache.buckets[node0Idx];
      FTCNodeRec linkNode = null;
      
      for (;;) {
        FTCNodeRec node;
        node = pnode;

        if (node == null) {
          FT_Trace.Trace(7, TAG, "ftc_node_hash_unlink: unknown node");
          return;
        }
        if (node == node0) {
          break;
        }
	linkNode = pnode;
        pnode = pnode.link;
      }
      if (linkNode == null) {
        cache.buckets[node0Idx] = cache.buckets[node0Idx].link;
      } else {
	linkNode.link = cache.buckets[node0Idx].link;
      }
      node0.link = null;
      cache.slack++;
      ftc_cache_resize(cache);
    }

    /* =====================================================================
     * ftc_node_hash_link
     * =====================================================================
     */
    /* add a node to the `top' of its cache's hash table */
    public static void ftc_node_hash_link(FTCNodeRec node, FTCCacheRec cache) {
      int nodeIdx = ftc_get_top_node_for_hash(cache, node.hash);
      FTCNodeRec pnode = cache.buckets[nodeIdx];
      
      node.link = pnode;
      cache.buckets[nodeIdx] = node;
      cache.slack--;
      ftc_cache_resize( cache );
    }

    /* =====================================================================
     * ftc_node_destroy
     * =====================================================================
     */
    public static void ftc_node_destroy(FTCNodeRec node, FTCManagerRec manager) {
      FTCCacheRec cache;

      /* find node's cache */
      if (node.cache_index >= manager.num_caches) {
        FT_Trace.Trace(7, TAG, "ftc_node_destroy: invalid node handle");
        return;
      }
      cache = manager.caches[node.cache_index];
      if (cache == null) {
        FT_Trace.Trace(7, TAG, "ftc_node_destroy: invalid node handle");
        return;
      }
      manager.cur_weight -= (int)cache.clazz.node_weight.callClassMethod(node, cache);
      /* remove node from mru list */
      ftc_node_mru_unlink(node, manager);
      /* remove node from cache's hash table */
      ftc_node_hash_unlink(node, cache);
      /* now finalize it */
      cache.clazz.node_free.callClassMethod(node, cache);
    }

}

Added ftcache/FTCMruListClassRec.java.

























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ----------------------------------------------------------------
// FTCMruListClassRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCMruListClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCMruListClassRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCMruListClassRec";
    public String initStr;
    public final static int NODE_TYPE_UNKNOWN = 0;
    public final static int NODE_TYPE_FTC_FACE_NODE_REC = 1;
    public final static int NODE_TYPE_FTC_SIZE_NODE_REC = 2;
    public final static int NODE_TYPE_FTC_GNODE_REC = 3;
    public final static int NODE_TYPE_FTC_INODE_REC = 4;
    public final static int NODE_TYPE_FTC_SNODE_REC = 5;
    public final static int NODE_TYPE_FTC_BASIC_FAMILY_REC = 6;
    
    public int node_type = NODE_TYPE_UNKNOWN;
    public TTInstanceMethod node_compare = null;
    public TTInstanceMethod node_init = null;
    public TTInstanceMethod node_reset = null;
    public TTInstanceMethod node_done = null;

    /* ==================== FTCMruListClassRec ================================== */
    public FTCMruListClassRec(String initStr) {
      super();
      oid++;
      id = oid;
      this.initStr = initStr;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"+"+initStr+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCMruListRec.java.























































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// ----------------------------------------------------------------
// FTCMruListRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

import android.util.Log;
//import org.apwtcl.gles20.truetype.*;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCMruListRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCMruListRec extends FTCMruListClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCMruListRec";

    public String initStr = null;
    
    public int num_nodes = 0;
    public int max_nodes = 0;
    public FTCMruNodeRec nodes = null;
    public Object data = null;

    /* ==================== FTCMruListRec ================================== */
    public FTCMruListRec(String initStr) {
      super("FTCMruListRec");
      oid++;
      id = oid;
      this.initStr = initStr;
    }
    
    /* ==================== FTCMruListRec ================================== */
    public FTCMruListRec(FTCMruListClassRec clazz, String initStr) {
      super("FTCMruListRec2");
      oid++;
      id = oid;
      this.initStr = initStr;
      node_compare = clazz.node_compare;
      node_init = clazz.node_init;
      node_reset = clazz.node_reset;
      node_done = clazz.node_done;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTCMruListInit
     * =====================================================================
     */
    public static int FTCMruListInit(FTCMruListRec list, FTCMruListClassRec mru, int max_nodes, Object data) {
      int error = 0;

Log.i(TAG, "FTCMruListInit: max_nodes: "+max_nodes+"!");
      list.num_nodes = 0;
      list.max_nodes = max_nodes;
      list.nodes = null;
      list.node_type = mru.node_type;
      list.node_compare = mru.node_compare;
      list.node_init = mru.node_init;
      list.node_reset = mru.node_reset;
      list.node_done = mru.node_done;
      list.data = data;
      return error;
    }

    /* =====================================================================
     * FTCMruListLookup
     * =====================================================================
     */
    public static int FTCMruListLookup(FTCMruListRec list, Object key, FTReference<Object> node_ref) {
      FTCMruNodeRec node;
      int error = 0;

      node = FTCMruListFind(list, key);
      if (node == null) {
        return FTCMruListNew(list, key, node_ref);
      }
      node_ref.Set(node);
      return error;
    }

    /* =====================================================================
     * FTCMruListFind
     * =====================================================================
     */
    public static FTCMruNodeRec FTCMruListFind(FTCMruListRec list, Object key) {
      TTInstanceMethod compare = list.node_compare;
      FTCMruNodeRec node;
      FTCMruNodeRec first;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCMruListFind");
}
      first = list.nodes;
      node = null;
      if (first != null) {
        node = list.nodes;
        do {
          if ((boolean)compare.callClassMethod(node, key)) {
            if (first != node) {
if (FTCCacheRec.cache_debug > 2) {
System.out.println("first: "+first+"!"+node+"!");            	
}
              FTCMruNodeRec.FTCMruNodeUp(list.nodes, node);
            }
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCMruListFind found: "+node+"!");
}
            return node;
          }
          node = list.nodes.next;
        } while (node != first);
      }
      return null;
    }

    /* =====================================================================
     * FTCMruListNew
     * =====================================================================
     */
    public static int FTCMruListNew(FTCMruListRec list, Object key, FTReference<Object> node_ref) {
      FTCMruNodeRec node = null;
      Object node_obj = node;
      int error = 0;

if (FTCCacheRec.cache_debug > 2) {
System.out.println(String.format("FTCMruListNew: list.num_nodes: %d list.max_nodes: %d", list.num_nodes, list.max_nodes));      
}
      if (list.num_nodes >= list.max_nodes && list.max_nodes > 0) {
        node = list.nodes.prev;
//        FT_ASSERT( node );
        if (list.node_reset != null) {
          node_ref.Set(list.nodes);
          FTCMruNodeRec.FTCMruNodeUp(list.nodes, node);
          list.nodes = (FTCMruNodeRec)node_ref.Get();
          error = (int)list.node_reset.callClassMethod(node, key, list.data);
          if (error != 0) {
            return error;
          }
        }
        node_ref.Set(list.nodes);
        FTCMruNodeRec.FTCMruNodeRemove(list.nodes, node);
        list.nodes = (FTCMruNodeRec)node_ref.Get();
        list.num_nodes--;
        if (list.node_done != null) {
          list.node_done.callClassMethod(node, list.data );
        }
      } else {
        switch(list.node_type) {
        case FTCMruListClassRec.NODE_TYPE_FTC_FACE_NODE_REC:
           node = (FTCMruNodeRec)new FTCFaceNodeRec();
           break;
        case FTCMruListClassRec.NODE_TYPE_FTC_SIZE_NODE_REC:
          node = (FTCMruNodeRec)new FTCSizeNodeRec();
          break;
        case FTCMruListClassRec.NODE_TYPE_FTC_GNODE_REC:
          node = (FTCMruNodeRec)new FTCGNodeRec();
          break;
        case FTCMruListClassRec.NODE_TYPE_FTC_INODE_REC:
          node = (FTCMruNodeRec)new FTCINodeRec();
          break;
        case FTCMruListClassRec.NODE_TYPE_FTC_SNODE_REC:
          node = (FTCMruNodeRec)new FTCSNodeRec();
          break;
        case FTCMruListClassRec.NODE_TYPE_FTC_BASIC_FAMILY_REC:
          node = (FTCMruNodeRec)new FTCBasicFamilyRec();
          break;
        default:
          Log.e(TAG, String.format("bad node_type %d in FTCMruListNew", list.node_type));
          break;
        }
        if (node == null) {
          node_ref.Set(node);
          return error;
        }
      }
      FTReference<Object> obj_ref = new FTReference<Object>();
      obj_ref.Set(node);
if (FTCCacheRec.cache_debug > 2) {
System.out.println("node_init: node: "+node+"!"+list.initStr+"!"+list.initStr);
System.out.println("node_init2: key: "+key+"!data: "+list.data+"!");
}
      error = (int)list.node_init.callClassMethod(obj_ref, key, list.data);
      node_obj = obj_ref.Get();
      if (error != 0) {
        if (list.node_done != null) {
          list.node_done.callClassMethod((FTCMruNodeRec)node_obj, list.data);
        }
//      FT_FREE( node );
        node_ref.Set(null);
        return error;
      }
if (FTCCacheRec.cache_debug > 2) {
System.out.println("list.nodes. "+list.nodes);
}
      FTReference<FTCMruNodeRec> nodes_ref = new FTReference<FTCMruNodeRec>();
      nodes_ref.Set(list.nodes);
      FTCMruNodeRec.FTCMruNodePrepend(nodes_ref, (FTCMruNodeRec)node_obj);
      list.nodes = nodes_ref.Get();
      list.num_nodes++;
      node_ref.Set(node_obj);
      return error;
    }

    /* =====================================================================
     * FTCMruListLookupCmp
     * =====================================================================
     */
    public static void FTCMruListLookupCmp(FTReference<FTCMruListRec> list_ref, Object key, TTInstanceMethod compare, FTCMruNodeRec node) {
      FTCMruListRec list = list_ref.Get();
      FTCMruNodeRec first = list.nodes;
      if (first == null) ;

    }
}

Added ftcache/FTCMruNodeRec.java.































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// ----------------------------------------------------------------
// FTCMruNodeRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCMruNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCMruNodeRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCMruNodeRec";

    public FTCMruNodeRec next = null;
    public FTCMruNodeRec prev = null;

    /* ==================== FTCMruNodeRec ================================== */
    public FTCMruNodeRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTCMruNodePrepend
     * =====================================================================
     */
    public static void FTCMruNodePrepend(FTReference<FTCMruNodeRec> nodes_ref, FTCMruNodeRec node) {
      FTCMruNodeRec first = nodes_ref.Get();
      
 
if (FTCCacheRec.cache_debug > 2) {
System.out.println("FTCMruNodePrepend"+first+"!"+node+"!");      
}
      if (first != null) {
        FTCMruNodeRec last = null;
        if (first.prev != null) {
          last = first.prev;
        }
        first.prev = node;
        if (last != null) {
          last.next = node;
        }
        node.next = first;
        if (last != null) {
          node.prev = last;
        } else {
          node.prev = null;
        }
      } else {
        node.next = node;
        node.prev = node;
      }
      first = node;
      nodes_ref.Set(first);
    }

    /* =====================================================================
     * FTCMruNodeRemove
     * =====================================================================
     */
    public static void FTCMruNodeRemove(FTCMruNodeRec first, FTCMruNodeRec node) {
      FTCMruNodeRec next;
      FTCMruNodeRec prev;

      prev = node.prev;
      next = node.next;
      
      prev.next = next;
      next.prev = prev;
      
      if (node == next) {
        node = null;
      } else {
        if (node == first) {
          first = node;
	      }
      }
    }

    /* =====================================================================
     * FTCMruNodeUp
     * =====================================================================
     */
    public static void FTCMruNodeUp(FTCMruNodeRec first, FTCMruNodeRec node) {

      if (first != node) {
        FTCMruNodeRec last;
        FTCMruNodeRec prev;
        FTCMruNodeRec next;

        prev = node.prev;
        next = node.next;
        prev.next = next;
        next.prev = prev;
        last = first.prev;
        last.next  = node;
        first.prev = node;
        node.next = first;
        node.prev = last;
      }
    }

}

Added ftcache/FTCNodeRec.java.



























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ----------------------------------------------------------------
// FTCNodeRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /* Each cache controls one or more cache nodes.  Each node is part of    */
  /* the global_lru list of the manager.  Its `data' field however is used */
  /* as a reference count for now.                                         */
  /*                                                                       */
  /* A node can be anything, depending on the type of information held by  */
  /* the cache.  It can be an individual glyph image, a set of bitmaps     */
  /* glyphs for a given size, some metrics, etc.                           */
  /*                                                                       */
  /* ===================================================================== */

  /* ===================================================================== */
  /*    FTCNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCNodeRec extends FTCMruNodeRec {
    private static int oid = 0;

    private int id;
    private final static int MAX_NODE_RECS = 1024;
    private static String TAG = "FTCNodeRec";

    public FTCNodeRec link = null;   /* used for hashing                   */
    public int hash = 0;             /* used for hashing too               */
    public short cache_index = 0;    /* index of cache the node belongs to */
    public short ref_count = 0;      /* reference count for this node      */

    /* ==================== FTCNodeRec ================================== */
    public FTCNodeRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }

}

Added ftcache/FTCSBitRec.java.















































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// ----------------------------------------------------------------
// FTCSBitRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;
import org.apwtcl.gles20.batikfont.ftraster.*;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCSBitRec                                                         */
  /* <Description>                                                         */
  /*    A very compact structure used to describe a small glyph bitmap.    */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    width     :: The bitmap width in pixels.                           */
  /*                                                                       */
  /*    height    :: The bitmap height in pixels.                          */
  /*                                                                       */
  /*    left      :: The horizontal distance from the pen position to the  */
  /*                 left bitmap border (a.k.a. `left side bearing', or    */
  /*                 `lsb').                                               */
  /*                                                                       */
  /*    top       :: The vertical distance from the pen position (on the   */
  /*                 baseline) to the upper bitmap border (a.k.a. `top     */
  /*                 side bearing').  The distance is positive for upwards */
  /*                 y~coordinates.                                        */
  /*                                                                       */
  /*    format    :: The format of the glyph bitmap (monochrome or gray).  */
  /*                                                                       */
  /*    max_grays :: Maximum gray level value (in the range 1 to~255).     */
  /*                                                                       */
  /*    pitch     :: The number of bytes per bitmap line.  May be positive */
  /*                 or negative.                                          */
  /*                                                                       */
  /*    xadvance  :: The horizontal advance width in pixels.               */
  /*                                                                       */
  /*    yadvance  :: The vertical advance height in pixels.                */
  /*                                                                       */
  /*    buffer    :: A pointer to the bitmap pixels.                       */
  /*                                                                       */
  /* ===================================================================== */

public class FTCSBitRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCSBitRec";

    public short width = 0;
    public short height = 0;
    public short left = 0;
    public short top = 0;
    public byte format = 0;
    public short max_grays = 0;
    public short pitch = 0;
    public short xadvance = 0;
    public short yadvance = 0;
    public byte[] buffer = null;

    /* ==================== FTCSBitRec ================================== */
    public FTCSBitRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTCSBitCacheLookupScaler
     * =====================================================================
     */
    public static int FTCSBitCacheLookupScaler(Object cache,
             FTCScalerRec scaler, Long load_flags, int glyphIndex,
             FTReference<FTCSBitRec> sbit_ref, FTReference<FTCNodeRec> node_ref) {
      int error = 0;
      FTCSBitRec sbit;
      FTCBasicQueryRec query = new FTCBasicQueryRec();
      FTCNodeRec node = null; /* make compiler happy */
      Object hash;

      if (node_ref != null) {
          node_ref.Set(null);
      }
      /* other argument checks delayed to FTC_Cache_Lookup */
      if (sbit_ref == null || scaler == null) {
          return FT_Error.GLYPH_INVALID_ARGUMENT;
      }
      sbit_ref.Set(null);
      /* FT_Load_Glyph(), FT_Load_Char() take FT_UInt flags */
//      if (load_flags > FT_UINT_MAX ) {
//        FT_TRACE1(( "FTC_ImageCache_LookupScaler: higher bits in load_flags" ));
//        FT_TRACE1(( "0x%x are dropped\n", (load_flags & ~((FT_ULong)FT_UINT_MAX)) ));
//      }
      query.attrs.scaler = scaler;
      query.attrs.load_flags = load_flags.intValue();
      /* beware, the hash must be the same for all glyph ranges! */
      hash = FTCHashFuncs.FTC_BASIC_ATTR_HASH(query.attrs) + glyphIndex / FTCSNodeRec.FTC_SBIT_ITEMS_PER_NODE;
      FTReference<FTCBasicQueryRec> query_ref = new FTReference<FTCBasicQueryRec>();
      query_ref.Set(query);
System.out.println("FTCSBitCacheLookupScaler: cache: "+(FTCGCacheRec)cache+"!"+((FTCGCacheRec)cache).families+"!");
      error = FTCGCacheRec.FTCGCacheLookup((FTCGCacheRec)cache, (int)hash, glyphIndex, (FTCGQueryRec)query, node_ref);
//      FTC_GCACHE_LOOKUP_CMP(cache, ftc_basic_family_compare, FTC_SNode_Compare,
//              hash, glyphIndex, query_ref, node, error );
//      query = query_ref.Get();
      node = node_ref.Get();    
      if (error != 0) {
        return error;
      }    
      sbit = ((FTCSNodeRec)(node)).sbits[(glyphIndex - ((FTCGNodeRec)node).gindex)];
      sbit_ref.Set(sbit);
      if (node_ref != null) {
        node_ref.Set(node);
        node.ref_count++;
      }
      return error;
    }

}

Added ftcache/FTCSFamilyClassRec.java.









































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ----------------------------------------------------------------
// FTCSFamilyClassRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCSFamilyClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCSFamilyClassRec extends FTCMruListClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCSFamilyClassRec";

    public TTInstanceMethod family_get_count = null;
    public TTInstanceMethod family_load_glyph = null;

    /* ==================== FTCSFamilyClassRec ================================== */
    public FTCSFamilyClassRec(String initStr) {
      super(initStr);
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * =====================================================================
     */

}

Added ftcache/FTCSNodeRec.java.

















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ----------------------------------------------------------------
// FTCSNodeRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCSNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCSNodeRec extends FTCGNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCSNodeRec";

    public final static int FTC_SBIT_ITEMS_PER_NODE = 16;

    public int count = 0;
    public FTCSBitRec[] sbits = new FTCSBitRec[FTC_SBIT_ITEMS_PER_NODE];

    /* ==================== FTCSNodeRec ================================== */
    public FTCSNodeRec() {
      oid++;
      id = oid;
      for (int i = 0; i < FTC_SBIT_ITEMS_PER_NODE; i++) {
        sbits[i] = new FTCSBitRec();
      }
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * =====================================================================
     */

}

Added ftcache/FTCScalerRec.java.











































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// ----------------------------------------------------------------
// FTCScalerRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCScalerRec                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A structure used to describe a given character size in either      */
  /*    pixels or points to the cache manager.  See                        */
  /*    @FTC_Manager_LookupSize.                                           */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    face_id :: The source face ID.                                     */
  /*                                                                       */
  /*    width   :: The character width.                                    */
  /*                                                                       */
  /*    height  :: The character height.                                   */
  /*                                                                       */
  /*    pixel   :: A Boolean.  If 1, the `width' and `height' fields are   */
  /*               interpreted as integer pixel character sizes.           */
  /*               Otherwise, they are expressed as 1/64th of points.      */
  /*                                                                       */
  /*    x_res   :: Only used when `pixel' is value~0 to indicate the       */
  /*               horizontal resolution in dpi.                           */
  /*                                                                       */
  /*    y_res   :: Only used when `pixel' is value~0 to indicate the       */
  /*               vertical resolution in dpi.                             */
  /*                                                                       */
  /* <Note>                                                                */
  /*    This type is mainly used to retrieve @FT_Size objects through the  */
  /*    cache manager.                                                     */
  /*                                                                       */
  /* ===================================================================== */

public class FTCScalerRec extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCScalerRec";

    public Object face_id = null;
    public int width = 0;
    public int height = 0;
    public int pixel = 0;
    public int x_res = 0;
    public int y_res = 0;

    /* ==================== FTCScalerRec ================================== */
    public FTCScalerRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * ftc_scaler_lookup_size
     * =====================================================================
     */
    public static int ftc_scaler_lookup_size(FTCManagerRec manager, FTCScalerRec scaler, FTReference<FTSizeRec> size_ref) {
      int error = 0;
      FTFaceRec face;
      FTSizeRec size = null;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("ftc_scaler_lookup_size");
}
      FTReference<FTFaceRec> face_ref = new FTReference<FTFaceRec>();
      error = FTCManagerRec.FTCManagerLookupFace(manager, scaler.face_id, face_ref);
      face = face_ref.Get();
      if (error != 0) {
        size_ref.Set(size);
        return error;
      }
      error = FTSizeRec.FTNewSize(face, size_ref);
      size = size_ref.Get();
      if (error != 0) {
        size_ref.Set(size);
        return error;
      }
      FTSizeRec.FTActivateSize(size);
      if (scaler.pixel != 0) {
        Log.w(TAG, "FTSetPixelSizes not yet implemented!!");
//        error = FTSetPixelSizes(face, scaler.width, scaler.height);
      } else {
        error = FTSizeRec.FTSetCharSize(face, scaler.width, scaler.height, scaler.x_res, scaler.y_res);
      }
      if (error != 0) {
//        FTSizeRec.FTDoneSize(size);
        size = null;
      }
      size_ref.Set(face.size);
      return error;
    }

}

Added ftcache/FTCSizeListClass.java.







































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// ----------------------------------------------------------------
// FTCSizeListClass.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCSizeListClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCSizeListClass extends FTCMruListClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCSizeListClass";

    /* ==================== FTCSizeListClass ================================== */
    public FTCSizeListClass() {
      super("FTCSizeListClass");
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTCSizeListFuncs";
      this.node_type = NODE_TYPE_FTC_SIZE_NODE_REC;
      this.node_compare = new TTInstanceMethod(class_name, "ftc_size_node_compare", 1);
      this.node_init    = new TTInstanceMethod(class_name, "ftc_size_node_init", 1);
      this.node_reset   = new TTInstanceMethod(class_name, "ftc_size_node_reset", 1);
      this.node_done    = new TTInstanceMethod(class_name, "ftc_size_node_done", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

Added ftcache/FTCSizeListFuncs.java.

























































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// ----------------------------------------------------------------
// FTCSizeListFuncs.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

import android.util.Log;
//import org.apwtcl.gles20.batikfont.ftraster.*;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf ont files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCSizeListFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTCSizeListFuncs extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCSizeListFuncs";
    
    /* ==================== FTCSizeListFuncs ================================== */
    public FTCSizeListFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ftc_size_node_compare
     *
     * =====================================================================
     */
    public static boolean ftc_size_node_compare(Object ... args) {
if (FTCCacheRec.cache_debug > 2) {
System.out.println("ftc_size_node_compare");
}
      FTCMruNodeRec ftcnode = (FTCMruNodeRec)args[0];
      Object ftcscaler = args[1];
      FTCSizeNodeRec node = (FTCSizeNodeRec)ftcnode;
      FTCScalerRec scaler = (FTCScalerRec)ftcscaler;
      FTCScalerRec scaler0 = node.scaler;

      if (scaler0.face_id == scaler.face_id &&
          scaler0.width == scaler.width &&
          scaler0.height == scaler.height &&
          (scaler0.pixel != 0) == (scaler.pixel != 0) &&
          (scaler0.pixel != 0 ||
            (scaler0.x_res == scaler.x_res && scaler0.y_res == scaler.y_res))) {
        FTSizeRec.FTActivateSize(node.size);
        return true;
      }
      return false;
    }

    /* =====================================================================
     *    ftc_size_node_init
     *
     * =====================================================================
     */
    public static int ftc_size_node_init(Object ... args) {
      FTReference<Object> obj_ref = (FTReference<Object>)args[0];
      FTCMruNodeRec ftcnode = (FTCMruNodeRec)obj_ref.Get();
      FTCScalerRec ftcscaler = (FTCScalerRec)args[1];
      FTCManagerRec ftcmanager = (FTCManagerRec)args[2];
      FTCSizeNodeRec size_node = (FTCSizeNodeRec)ftcnode;
      int error = 0;

if (FTCCacheRec.cache_debug > 2) {
System.out.println("ftc_size_node_init");
}
      size_node.scaler = ftcscaler;
      FTReference<FTSizeRec> size_ref = new FTReference<FTSizeRec>();
      error = FTCScalerRec.ftc_scaler_lookup_size(ftcmanager, ftcscaler, size_ref);
      size_node.size = size_ref.Get();
      obj_ref.Set(size_node);
      return error;
    }

    /* =====================================================================
     *    ftc_size_node_reset
     *
     * =====================================================================
     */
    public static int ftc_size_node_reset(Object ... args) {
      Log.w(TAG, "ftc_size_node_reset not yet implemented");
//      Object obj = args[0];

      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ftc_size_node_done
     *
     * =====================================================================
     */
    public static int ftc_size_node_done(Object ... args) {
      Log.w(TAG, "ftc_size_node_done not yet implemented");
//      Object obj = args[0];

      int error = 0;

      return error;
    }

}

Added ftcache/FTCSizeNodeRec.java.





























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ----------------------------------------------------------------
// FTCSizeNodeRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftcache;

//import android.util.Log;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTCSizeNodeRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTCSizeNodeRec extends FTCMruNodeRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTCSizeNodeRec";

    public FTSizeRec size = null;
    public FTCScalerRec scaler = null;

    /* ==================== FTCSizeNodeRec ================================== */
    public FTCSizeNodeRec() {
      oid++;
      id = oid;
    }
    
    /* ==================== FTCSizeNodeRec ================================== */
    public FTCSizeNodeRec(FTCMruNodeRec node) {
      oid++;
      id = oid;
      
      this.next = node.next;
      this.prev = node.prev;;
      size = new FTSizeRec();
      scaler = new FTCScalerRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * =====================================================================
     */

}