diff options
| author | K. Handa | 2015-09-01 20:44:51 +0900 |
|---|---|---|
| committer | K. Handa | 2015-09-01 20:44:51 +0900 |
| commit | 524eeb2e5e158d98ea52fe5ebe4768c4433ba8b2 (patch) | |
| tree | 122ddb9850f703ddc8e2f1615d1b3101f426300d /src | |
| parent | fdd095d2fd79f73ec96b9d318248e6ad70931b4a (diff) | |
| download | emacs-524eeb2e5e158d98ea52fe5ebe4768c4433ba8b2.tar.gz emacs-524eeb2e5e158d98ea52fe5ebe4768c4433ba8b2.zip | |
Use the new type MFLTGlyphFT for MFLTGlyphString.glyphs.
* ftfont.c (MFLTGlyphFT): New type.
(ftfont_get_glyph_id, ftfont_get_metrics, ftfont_drive_otf)
(ftfont_shape_by_flt): Make MFLTGlyphFT the actual type of
elements in the array MFLTGlyphString.glyphs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftfont.c | 339 |
1 files changed, 208 insertions, 131 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index 41d99dffeb6..885fee61ba1 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -1574,21 +1574,33 @@ struct MFLTFontFT | |||
| 1574 | FT_Matrix *matrix; | 1574 | FT_Matrix *matrix; |
| 1575 | }; | 1575 | }; |
| 1576 | 1576 | ||
| 1577 | /* The actual type of elements in the array MFLTGlyphString.glyphs. | ||
| 1578 | We use this structure instead of MFLTGlyph to utilize the new | ||
| 1579 | feature of libotf ver.0.9.15 which requires saving and restoring | ||
| 1580 | the value of OTF_GlyphString.positioning_type in the succeeding | ||
| 1581 | calls of the callback function MFLTFont.drive_otf (which is set to | ||
| 1582 | ftfont_drive_otf). */ | ||
| 1583 | |||
| 1584 | typedef struct { | ||
| 1585 | MFLTGlyph g; | ||
| 1586 | unsigned int libotf_positioning_type; | ||
| 1587 | } MFLTGlyphFT; | ||
| 1588 | |||
| 1577 | static int | 1589 | static int |
| 1578 | ftfont_get_glyph_id (MFLTFont *font, MFLTGlyphString *gstring, | 1590 | ftfont_get_glyph_id (MFLTFont *font, MFLTGlyphString *gstring, |
| 1579 | int from, int to) | 1591 | int from, int to) |
| 1580 | { | 1592 | { |
| 1581 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | 1593 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; |
| 1582 | FT_Face ft_face = flt_font_ft->ft_face; | 1594 | FT_Face ft_face = flt_font_ft->ft_face; |
| 1583 | MFLTGlyph *g; | 1595 | MFLTGlyphFT *g; |
| 1584 | 1596 | ||
| 1585 | for (g = gstring->glyphs + from; from < to; g++, from++) | 1597 | for (g = (MFLTGlyphFT *) (gstring->glyphs) + from; from < to; g++, from++) |
| 1586 | if (! g->encoded) | 1598 | if (! g->g.encoded) |
| 1587 | { | 1599 | { |
| 1588 | FT_UInt code = FT_Get_Char_Index (ft_face, g->code); | 1600 | FT_UInt code = FT_Get_Char_Index (ft_face, g->g.code); |
| 1589 | 1601 | ||
| 1590 | g->code = code > 0 ? code : FONT_INVALID_CODE; | 1602 | g->g.code = code > 0 ? code : FONT_INVALID_CODE; |
| 1591 | g->encoded = 1; | 1603 | g->g.encoded = 1; |
| 1592 | } | 1604 | } |
| 1593 | return 0; | 1605 | return 0; |
| 1594 | } | 1606 | } |
| @@ -1605,16 +1617,16 @@ ftfont_get_metrics (MFLTFont *font, MFLTGlyphString *gstring, | |||
| 1605 | { | 1617 | { |
| 1606 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | 1618 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; |
| 1607 | FT_Face ft_face = flt_font_ft->ft_face; | 1619 | FT_Face ft_face = flt_font_ft->ft_face; |
| 1608 | MFLTGlyph *g; | 1620 | MFLTGlyphFT *g; |
| 1609 | 1621 | ||
| 1610 | for (g = gstring->glyphs + from; from < to; g++, from++) | 1622 | for (g = (MFLTGlyphFT *) (gstring->glyphs) + from; from < to; g++, from++) |
| 1611 | if (! g->measured) | 1623 | if (! g->g.measured) |
| 1612 | { | 1624 | { |
| 1613 | if (g->code != FONT_INVALID_CODE) | 1625 | if (g->g.code != FONT_INVALID_CODE) |
| 1614 | { | 1626 | { |
| 1615 | FT_Glyph_Metrics *m; | 1627 | FT_Glyph_Metrics *m; |
| 1616 | 1628 | ||
| 1617 | if (FT_Load_Glyph (ft_face, g->code, FT_LOAD_DEFAULT) != 0) | 1629 | if (FT_Load_Glyph (ft_face, g->g.code, FT_LOAD_DEFAULT) != 0) |
| 1618 | emacs_abort (); | 1630 | emacs_abort (); |
| 1619 | m = &ft_face->glyph->metrics; | 1631 | m = &ft_face->glyph->metrics; |
| 1620 | if (flt_font_ft->matrix) | 1632 | if (flt_font_ft->matrix) |
| @@ -1628,29 +1640,29 @@ ftfont_get_metrics (MFLTFont *font, MFLTGlyphString *gstring, | |||
| 1628 | v[1].y = v[3].y = m->horiBearingY - m->height; | 1640 | v[1].y = v[3].y = m->horiBearingY - m->height; |
| 1629 | for (i = 0; i < 4; i++) | 1641 | for (i = 0; i < 4; i++) |
| 1630 | FT_Vector_Transform (v + i, flt_font_ft->matrix); | 1642 | FT_Vector_Transform (v + i, flt_font_ft->matrix); |
| 1631 | g->lbearing = v[0].x < v[1].x ? FLOOR (v[0].x) : FLOOR (v[1].x); | 1643 | g->g.lbearing = v[0].x < v[1].x ? FLOOR (v[0].x) : FLOOR (v[1].x); |
| 1632 | g->rbearing = v[2].x > v[3].x ? CEIL (v[2].x) : CEIL (v[3].x); | 1644 | g->g.rbearing = v[2].x > v[3].x ? CEIL (v[2].x) : CEIL (v[3].x); |
| 1633 | g->ascent = v[0].y > v[2].y ? CEIL (v[0].y) : CEIL (v[2].y); | 1645 | g->g.ascent = v[0].y > v[2].y ? CEIL (v[0].y) : CEIL (v[2].y); |
| 1634 | g->descent = v[1].y < v[3].y ? - FLOOR (v[1].y) : - FLOOR (v[3].y); | 1646 | g->g.descent = v[1].y < v[3].y ? - FLOOR (v[1].y) : - FLOOR (v[3].y); |
| 1635 | } | 1647 | } |
| 1636 | else | 1648 | else |
| 1637 | { | 1649 | { |
| 1638 | g->lbearing = FLOOR (m->horiBearingX); | 1650 | g->g.lbearing = FLOOR (m->horiBearingX); |
| 1639 | g->rbearing = CEIL (m->horiBearingX + m->width); | 1651 | g->g.rbearing = CEIL (m->horiBearingX + m->width); |
| 1640 | g->ascent = CEIL (m->horiBearingY); | 1652 | g->g.ascent = CEIL (m->horiBearingY); |
| 1641 | g->descent = - FLOOR (m->horiBearingY - m->height); | 1653 | g->g.descent = - FLOOR (m->horiBearingY - m->height); |
| 1642 | } | 1654 | } |
| 1643 | g->xadv = ROUND (ft_face->glyph->advance.x); | 1655 | g->g.xadv = ROUND (ft_face->glyph->advance.x); |
| 1644 | } | 1656 | } |
| 1645 | else | 1657 | else |
| 1646 | { | 1658 | { |
| 1647 | g->lbearing = 0; | 1659 | g->g.lbearing = 0; |
| 1648 | g->rbearing = g->xadv = flt_font_ft->font->space_width << 6; | 1660 | g->g.rbearing = g->g.xadv = flt_font_ft->font->space_width << 6; |
| 1649 | g->ascent = flt_font_ft->font->ascent << 6; | 1661 | g->g.ascent = flt_font_ft->font->ascent << 6; |
| 1650 | g->descent = flt_font_ft->font->descent << 6; | 1662 | g->g.descent = flt_font_ft->font->descent << 6; |
| 1651 | } | 1663 | } |
| 1652 | g->yadv = 0; | 1664 | g->g.yadv = 0; |
| 1653 | g->measured = 1; | 1665 | g->g.measured = 1; |
| 1654 | } | 1666 | } |
| 1655 | return 0; | 1667 | return 0; |
| 1656 | } | 1668 | } |
| @@ -1801,6 +1813,8 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1801 | MFLTGlyphAdjustment *adjustment) | 1813 | MFLTGlyphAdjustment *adjustment) |
| 1802 | { | 1814 | { |
| 1803 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | 1815 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; |
| 1816 | MFLTGlyphFT *in_glyphs = (MFLTGlyphFT *) (in->glyphs) + from; | ||
| 1817 | MFLTGlyphFT *out_glyphs = out ? (MFLTGlyphFT *) (out->glyphs) : NULL; | ||
| 1804 | FT_Face ft_face = flt_font_ft->ft_face; | 1818 | FT_Face ft_face = flt_font_ft->ft_face; |
| 1805 | OTF *otf = flt_font_ft->otf; | 1819 | OTF *otf = flt_font_ft->otf; |
| 1806 | int len = to - from; | 1820 | int len = to - from; |
| @@ -1852,8 +1866,11 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1852 | setup_otf_gstring (len); | 1866 | setup_otf_gstring (len); |
| 1853 | for (i = 0; i < len; i++) | 1867 | for (i = 0; i < len; i++) |
| 1854 | { | 1868 | { |
| 1855 | otf_gstring.glyphs[i].c = in->glyphs[from + i].c & 0x11FFFF; | 1869 | otf_gstring.glyphs[i].c = in_glyphs[i].g.c & 0x11FFFF; |
| 1856 | otf_gstring.glyphs[i].glyph_id = in->glyphs[from + i].code; | 1870 | otf_gstring.glyphs[i].glyph_id = in_glyphs[i].g.code; |
| 1871 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 1872 | otf_gstring.glyphs[i].positioning_type = in_glyphs[i].libotf_positioning_type; | ||
| 1873 | #endif | ||
| 1857 | } | 1874 | } |
| 1858 | 1875 | ||
| 1859 | OTF_drive_gdef (otf, &otf_gstring); | 1876 | OTF_drive_gdef (otf, &otf_gstring); |
| @@ -1861,9 +1878,15 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1861 | 1878 | ||
| 1862 | if (gsub_features && out) | 1879 | if (gsub_features && out) |
| 1863 | { | 1880 | { |
| 1881 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 1882 | if (OTF_drive_gsub_features (otf, &otf_gstring, script, langsys, | ||
| 1883 | gsub_features) < 0) | ||
| 1884 | goto simple_copy; | ||
| 1885 | #else | ||
| 1864 | if (OTF_drive_gsub_with_log (otf, &otf_gstring, script, langsys, | 1886 | if (OTF_drive_gsub_with_log (otf, &otf_gstring, script, langsys, |
| 1865 | gsub_features) < 0) | 1887 | gsub_features) < 0) |
| 1866 | goto simple_copy; | 1888 | goto simple_copy; |
| 1889 | #endif | ||
| 1867 | if (out->allocated < out->used + otf_gstring.used) | 1890 | if (out->allocated < out->used + otf_gstring.used) |
| 1868 | { | 1891 | { |
| 1869 | SAFE_FREE (); | 1892 | SAFE_FREE (); |
| @@ -1872,59 +1895,67 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1872 | features = otf->gsub->FeatureList.Feature; | 1895 | features = otf->gsub->FeatureList.Feature; |
| 1873 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; ) | 1896 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; ) |
| 1874 | { | 1897 | { |
| 1875 | MFLTGlyph *g; | 1898 | MFLTGlyphFT *g; |
| 1876 | int min_from, max_to; | 1899 | int min_from, max_to; |
| 1877 | int feature_idx = otfg->positioning_type >> 4; | 1900 | int feature_idx; |
| 1878 | 1901 | ||
| 1879 | g = out->glyphs + out->used; | 1902 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT |
| 1880 | *g = in->glyphs[from + otfg->f.index.from]; | 1903 | feature_idx = OTF_POSITIONING_TYPE_GET_FEATURE (otfg); |
| 1881 | if (g->code != otfg->glyph_id) | 1904 | #else |
| 1905 | feature_idx = otfg->positioning_type >> 4; | ||
| 1906 | #endif | ||
| 1907 | g = out_glyphs + out->used; | ||
| 1908 | *g = in_glyphs[otfg->f.index.from]; | ||
| 1909 | if (g->g.code != otfg->glyph_id) | ||
| 1882 | { | 1910 | { |
| 1883 | g->c = 0; | 1911 | g->g.c = 0; |
| 1884 | g->code = otfg->glyph_id; | 1912 | g->g.code = otfg->glyph_id; |
| 1885 | g->measured = 0; | 1913 | g->g.measured = 0; |
| 1886 | } | 1914 | } |
| 1887 | out->used++; | 1915 | out->used++; |
| 1888 | min_from = g->from; | 1916 | min_from = g->g.from; |
| 1889 | max_to = g->to; | 1917 | max_to = g->g.to; |
| 1890 | if (otfg->f.index.from < otfg->f.index.to) | 1918 | if (otfg->f.index.from < otfg->f.index.to) |
| 1891 | { | 1919 | { |
| 1892 | /* OTFG substitutes multiple glyphs in IN. */ | 1920 | /* OTFG substitutes multiple glyphs in IN. */ |
| 1893 | for (j = from + otfg->f.index.from + 1; | 1921 | for (j = otfg->f.index.from + 1; j <= otfg->f.index.to; j++) |
| 1894 | j <= from + otfg->f.index.to; j++) | ||
| 1895 | { | 1922 | { |
| 1896 | if (min_from > in->glyphs[j].from) | 1923 | if (min_from > in_glyphs[j].g.from) |
| 1897 | min_from = in->glyphs[j].from; | 1924 | min_from = in_glyphs[j].g.from; |
| 1898 | if (max_to < in->glyphs[j].to) | 1925 | if (max_to < in_glyphs[j].g.to) |
| 1899 | max_to = in->glyphs[j].to; | 1926 | max_to = in_glyphs[j].g.to; |
| 1900 | } | 1927 | } |
| 1901 | g->from = min_from; | 1928 | g->g.from = min_from; |
| 1902 | g->to = max_to; | 1929 | g->g.to = max_to; |
| 1903 | } | 1930 | } |
| 1904 | if (feature_idx) | 1931 | if (feature_idx) |
| 1905 | { | 1932 | { |
| 1906 | unsigned int tag = features[feature_idx - 1].FeatureTag; | 1933 | unsigned int tag = features[feature_idx - 1].FeatureTag; |
| 1907 | tag = PACK_OTF_TAG (tag); | 1934 | tag = PACK_OTF_TAG (tag); |
| 1908 | g->internal = (g->internal & ~0x1FFFFFFF) | tag; | 1935 | g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag; |
| 1909 | } | 1936 | } |
| 1910 | for (i++, otfg++; (i < otf_gstring.used | 1937 | for (i++, otfg++; (i < otf_gstring.used |
| 1911 | && otfg->f.index.from == otfg[-1].f.index.from); | 1938 | && otfg->f.index.from == otfg[-1].f.index.from); |
| 1912 | i++, otfg++) | 1939 | i++, otfg++) |
| 1913 | { | 1940 | { |
| 1914 | g = out->glyphs + out->used; | 1941 | g = out_glyphs + out->used; |
| 1915 | *g = in->glyphs[from + otfg->f.index.to]; | 1942 | *g = in_glyphs[otfg->f.index.to]; |
| 1916 | if (g->code != otfg->glyph_id) | 1943 | if (g->g.code != otfg->glyph_id) |
| 1917 | { | 1944 | { |
| 1918 | g->c = 0; | 1945 | g->g.c = 0; |
| 1919 | g->code = otfg->glyph_id; | 1946 | g->g.code = otfg->glyph_id; |
| 1920 | g->measured = 0; | 1947 | g->g.measured = 0; |
| 1921 | } | 1948 | } |
| 1949 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 1950 | feature_idx = OTF_POSITIONING_TYPE_GET_FEATURE (otfg); | ||
| 1951 | #else | ||
| 1922 | feature_idx = otfg->positioning_type >> 4; | 1952 | feature_idx = otfg->positioning_type >> 4; |
| 1953 | #endif | ||
| 1923 | if (feature_idx) | 1954 | if (feature_idx) |
| 1924 | { | 1955 | { |
| 1925 | unsigned int tag = features[feature_idx - 1].FeatureTag; | 1956 | unsigned int tag = features[feature_idx - 1].FeatureTag; |
| 1926 | tag = PACK_OTF_TAG (tag); | 1957 | tag = PACK_OTF_TAG (tag); |
| 1927 | g->internal = (g->internal & ~0x1FFFFFFF) | tag; | 1958 | g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag; |
| 1928 | } | 1959 | } |
| 1929 | out->used++; | 1960 | out->used++; |
| 1930 | } | 1961 | } |
| @@ -1933,23 +1964,33 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1933 | else if (gsub_features) | 1964 | else if (gsub_features) |
| 1934 | { | 1965 | { |
| 1935 | /* Just for checking which features will be applied. */ | 1966 | /* Just for checking which features will be applied. */ |
| 1967 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 1968 | if (OTF_drive_gsub_features (otf, &otf_gstring, script, langsys, | ||
| 1969 | gsub_features) < 0) | ||
| 1970 | goto simple_copy; | ||
| 1971 | #else | ||
| 1936 | if (OTF_drive_gsub_with_log (otf, &otf_gstring, script, langsys, | 1972 | if (OTF_drive_gsub_with_log (otf, &otf_gstring, script, langsys, |
| 1937 | gsub_features) < 0) | 1973 | gsub_features) < 0) |
| 1938 | goto simple_copy; | 1974 | goto simple_copy; |
| 1975 | #endif | ||
| 1939 | features = otf->gsub->FeatureList.Feature; | 1976 | features = otf->gsub->FeatureList.Feature; |
| 1940 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; i++, | 1977 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; i++, |
| 1941 | otfg++) | 1978 | otfg++) |
| 1942 | { | 1979 | { |
| 1943 | int feature_idx = otfg->positioning_type >> 4; | 1980 | int feature_idx; |
| 1944 | 1981 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | |
| 1982 | feature_idx = OTF_POSITIONING_TYPE_GET_FEATURE (otfg); | ||
| 1983 | #else | ||
| 1984 | feature_idx = otfg->positioning_type >> 4; | ||
| 1985 | #endif | ||
| 1945 | if (feature_idx) | 1986 | if (feature_idx) |
| 1946 | { | 1987 | { |
| 1947 | unsigned int tag = features[feature_idx - 1].FeatureTag; | 1988 | unsigned int tag = features[feature_idx - 1].FeatureTag; |
| 1948 | tag = PACK_OTF_TAG (tag); | 1989 | tag = PACK_OTF_TAG (tag); |
| 1949 | for (j = otfg->f.index.from; j <= otfg->f.index.to; j++) | 1990 | for (j = otfg->f.index.from; j <= otfg->f.index.to; j++) |
| 1950 | { | 1991 | { |
| 1951 | MFLTGlyph *g = in->glyphs + (from + j); | 1992 | MFLTGlyphFT *g = in_glyphs + j; |
| 1952 | g->internal = (g->internal & ~0x1FFFFFFF) | tag; | 1993 | g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag; |
| 1953 | } | 1994 | } |
| 1954 | } | 1995 | } |
| 1955 | } | 1996 | } |
| @@ -1962,42 +2003,61 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1962 | return -2; | 2003 | return -2; |
| 1963 | } | 2004 | } |
| 1964 | for (i = 0; i < len; i++) | 2005 | for (i = 0; i < len; i++) |
| 1965 | out->glyphs[out->used++] = in->glyphs[from + i]; | 2006 | out_glyphs[out->used++] = in_glyphs[i]; |
| 1966 | } | 2007 | } |
| 1967 | 2008 | ||
| 1968 | if (gpos_features && out) | 2009 | if (gpos_features && out) |
| 1969 | { | 2010 | { |
| 1970 | MFLTGlyph *base = NULL, *mark = NULL, *g; | 2011 | MFLTGlyphFT *base = NULL, *mark = NULL, *g; |
| 1971 | int x_ppem, y_ppem, x_scale, y_scale; | 2012 | int x_ppem, y_ppem, x_scale, y_scale; |
| 1972 | 2013 | ||
| 2014 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 2015 | if (OTF_drive_gpos_features (otf, &otf_gstring, script, langsys, | ||
| 2016 | gpos_features) < 0) | ||
| 2017 | { | ||
| 2018 | SAFE_FREE (); | ||
| 2019 | return to; | ||
| 2020 | } | ||
| 2021 | #else | ||
| 1973 | if (OTF_drive_gpos_with_log (otf, &otf_gstring, script, langsys, | 2022 | if (OTF_drive_gpos_with_log (otf, &otf_gstring, script, langsys, |
| 1974 | gpos_features) < 0) | 2023 | gpos_features) < 0) |
| 1975 | { | 2024 | { |
| 1976 | SAFE_FREE (); | 2025 | SAFE_FREE (); |
| 1977 | return to; | 2026 | return to; |
| 1978 | } | 2027 | } |
| 2028 | #endif | ||
| 1979 | features = otf->gpos->FeatureList.Feature; | 2029 | features = otf->gpos->FeatureList.Feature; |
| 1980 | x_ppem = ft_face->size->metrics.x_ppem; | 2030 | x_ppem = ft_face->size->metrics.x_ppem; |
| 1981 | y_ppem = ft_face->size->metrics.y_ppem; | 2031 | y_ppem = ft_face->size->metrics.y_ppem; |
| 1982 | x_scale = ft_face->size->metrics.x_scale; | 2032 | x_scale = ft_face->size->metrics.x_scale; |
| 1983 | y_scale = ft_face->size->metrics.y_scale; | 2033 | y_scale = ft_face->size->metrics.y_scale; |
| 1984 | 2034 | ||
| 1985 | for (i = 0, otfg = otf_gstring.glyphs, g = out->glyphs + gidx; | 2035 | for (i = 0, otfg = otf_gstring.glyphs, g = out_glyphs + gidx; |
| 1986 | i < otf_gstring.used; i++, otfg++, g++) | 2036 | i < otf_gstring.used; i++, otfg++) |
| 1987 | { | 2037 | { |
| 1988 | MFLTGlyph *prev; | 2038 | MFLTGlyphAdjustment *adjust = adjustment; |
| 1989 | int feature_idx = otfg->positioning_type >> 4; | 2039 | MFLTGlyphFT *prev; |
| 2040 | int positioning_type, feature_idx; | ||
| 1990 | 2041 | ||
| 2042 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 2043 | positioning_type = OTF_POSITIONING_TYPE_GET_FORMAT (otfg); | ||
| 2044 | feature_idx = OTF_POSITIONING_TYPE_GET_FEATURE (otfg); | ||
| 2045 | #else | ||
| 2046 | positioning_type = otfg->positioning_type & 0xF; | ||
| 2047 | feature_idx = otfg->positioning_type >> 4; | ||
| 2048 | #endif | ||
| 1991 | if (feature_idx) | 2049 | if (feature_idx) |
| 1992 | { | 2050 | { |
| 1993 | unsigned int tag = features[feature_idx - 1].FeatureTag; | 2051 | unsigned int tag = features[feature_idx - 1].FeatureTag; |
| 1994 | tag = PACK_OTF_TAG (tag); | 2052 | tag = PACK_OTF_TAG (tag); |
| 1995 | g->internal = (g->internal & ~0x1FFFFFFF) | tag; | 2053 | g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag; |
| 1996 | } | 2054 | } |
| 1997 | 2055 | ||
| 1998 | if (! otfg->glyph_id) | 2056 | if (! otfg->glyph_id) |
| 1999 | continue; | 2057 | /* This is a pseudo glyph that contains positioning |
| 2000 | switch (otfg->positioning_type & 0xF) | 2058 | information to be accumulated to a real glyph. */ |
| 2059 | adjust--; | ||
| 2060 | switch (positioning_type) | ||
| 2001 | { | 2061 | { |
| 2002 | case 0: | 2062 | case 0: |
| 2003 | break; | 2063 | break; |
| @@ -2007,30 +2067,30 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 2007 | int format = otfg->f.f1.format; | 2067 | int format = otfg->f.f1.format; |
| 2008 | 2068 | ||
| 2009 | if (format & OTF_XPlacement) | 2069 | if (format & OTF_XPlacement) |
| 2010 | adjustment[i].xoff | 2070 | adjust->xoff |
| 2011 | = otfg->f.f1.value->XPlacement * x_scale / 0x10000; | 2071 | = otfg->f.f1.value->XPlacement * x_scale / 0x10000; |
| 2012 | if (format & OTF_XPlaDevice) | 2072 | if (format & OTF_XPlaDevice) |
| 2013 | adjustment[i].xoff | 2073 | adjust->xoff |
| 2014 | += DEVICE_DELTA (otfg->f.f1.value->XPlaDevice, x_ppem); | 2074 | += DEVICE_DELTA (otfg->f.f1.value->XPlaDevice, x_ppem); |
| 2015 | if (format & OTF_YPlacement) | 2075 | if (format & OTF_YPlacement) |
| 2016 | adjustment[i].yoff | 2076 | adjust->yoff |
| 2017 | = - (otfg->f.f1.value->YPlacement * y_scale / 0x10000); | 2077 | = - (otfg->f.f1.value->YPlacement * y_scale / 0x10000); |
| 2018 | if (format & OTF_YPlaDevice) | 2078 | if (format & OTF_YPlaDevice) |
| 2019 | adjustment[i].yoff | 2079 | adjust->yoff |
| 2020 | -= DEVICE_DELTA (otfg->f.f1.value->YPlaDevice, y_ppem); | 2080 | -= DEVICE_DELTA (otfg->f.f1.value->YPlaDevice, y_ppem); |
| 2021 | if (format & OTF_XAdvance) | 2081 | if (format & OTF_XAdvance) |
| 2022 | adjustment[i].xadv | 2082 | adjust->xadv |
| 2023 | += otfg->f.f1.value->XAdvance * x_scale / 0x10000; | 2083 | += otfg->f.f1.value->XAdvance * x_scale / 0x10000; |
| 2024 | if (format & OTF_XAdvDevice) | 2084 | if (format & OTF_XAdvDevice) |
| 2025 | adjustment[i].xadv | 2085 | adjust->xadv |
| 2026 | += DEVICE_DELTA (otfg->f.f1.value->XAdvDevice, x_ppem); | 2086 | += DEVICE_DELTA (otfg->f.f1.value->XAdvDevice, x_ppem); |
| 2027 | if (format & OTF_YAdvance) | 2087 | if (format & OTF_YAdvance) |
| 2028 | adjustment[i].yadv | 2088 | adjust->yadv |
| 2029 | += otfg->f.f1.value->YAdvance * y_scale / 0x10000; | 2089 | += otfg->f.f1.value->YAdvance * y_scale / 0x10000; |
| 2030 | if (format & OTF_YAdvDevice) | 2090 | if (format & OTF_YAdvDevice) |
| 2031 | adjustment[i].yadv | 2091 | adjust->yadv |
| 2032 | += DEVICE_DELTA (otfg->f.f1.value->YAdvDevice, y_ppem); | 2092 | += DEVICE_DELTA (otfg->f.f1.value->YAdvDevice, y_ppem); |
| 2033 | adjustment[i].set = 1; | 2093 | adjust->set = 1; |
| 2034 | } | 2094 | } |
| 2035 | break; | 2095 | break; |
| 2036 | case 3: /* Cursive */ | 2096 | case 3: /* Cursive */ |
| @@ -2046,6 +2106,18 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 2046 | if (! mark) | 2106 | if (! mark) |
| 2047 | break; | 2107 | break; |
| 2048 | prev = mark; | 2108 | prev = mark; |
| 2109 | #ifdef OTF_POSITIONING_TYPE_GET_FORMAT | ||
| 2110 | { | ||
| 2111 | int distance = OTF_POSITIONING_TYPE_GET_MARKDISTANCE (otfg); | ||
| 2112 | |||
| 2113 | if (distance > 0) | ||
| 2114 | { | ||
| 2115 | prev = g - distance; | ||
| 2116 | if (prev < out_glyphs) | ||
| 2117 | prev = mark; | ||
| 2118 | } | ||
| 2119 | } | ||
| 2120 | #endif | ||
| 2049 | 2121 | ||
| 2050 | label_adjust_anchor: | 2122 | label_adjust_anchor: |
| 2051 | { | 2123 | { |
| @@ -2058,39 +2130,43 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 2058 | mark_y = otfg->f.f4.mark_anchor->YCoordinate * y_scale / 0x10000; | 2130 | mark_y = otfg->f.f4.mark_anchor->YCoordinate * y_scale / 0x10000; |
| 2059 | 2131 | ||
| 2060 | if (otfg->f.f4.base_anchor->AnchorFormat != 1) | 2132 | if (otfg->f.f4.base_anchor->AnchorFormat != 1) |
| 2061 | adjust_anchor (ft_face, otfg->f.f4.base_anchor, | 2133 | adjust_anchor (ft_face, otfg->f.f4.base_anchor, prev->g.code, |
| 2062 | prev->code, x_ppem, y_ppem, &base_x, &base_y); | 2134 | x_ppem, y_ppem, &base_x, &base_y); |
| 2063 | if (otfg->f.f4.mark_anchor->AnchorFormat != 1) | 2135 | if (otfg->f.f4.mark_anchor->AnchorFormat != 1) |
| 2064 | adjust_anchor (ft_face, otfg->f.f4.mark_anchor, g->code, | 2136 | adjust_anchor (ft_face, otfg->f.f4.mark_anchor, g->g.code, |
| 2065 | x_ppem, y_ppem, &mark_x, &mark_y); | 2137 | x_ppem, y_ppem, &mark_x, &mark_y); |
| 2066 | adjustment[i].xoff = (base_x - mark_x); | 2138 | adjust->xoff = (base_x - mark_x); |
| 2067 | adjustment[i].yoff = - (base_y - mark_y); | 2139 | adjust->yoff = - (base_y - mark_y); |
| 2068 | adjustment[i].back = (g - prev); | 2140 | adjust->back = (g - prev); |
| 2069 | adjustment[i].xadv = 0; | 2141 | adjust->xadv = 0; |
| 2070 | adjustment[i].advance_is_absolute = 1; | 2142 | adjust->advance_is_absolute = 1; |
| 2071 | adjustment[i].set = 1; | 2143 | adjust->set = 1; |
| 2072 | this_from = g->from; | 2144 | this_from = g->g.from; |
| 2073 | this_to = g->to; | 2145 | this_to = g->g.to; |
| 2074 | for (j = 0; prev + j < g; j++) | 2146 | for (j = 0; prev + j < g; j++) |
| 2075 | { | 2147 | { |
| 2076 | if (this_from > prev[j].from) | 2148 | if (this_from > prev[j].g.from) |
| 2077 | this_from = prev[j].from; | 2149 | this_from = prev[j].g.from; |
| 2078 | if (this_to < prev[j].to) | 2150 | if (this_to < prev[j].g.to) |
| 2079 | this_to = prev[j].to; | 2151 | this_to = prev[j].g.to; |
| 2080 | } | 2152 | } |
| 2081 | for (; prev <= g; prev++) | 2153 | for (; prev <= g; prev++) |
| 2082 | { | 2154 | { |
| 2083 | prev->from = this_from; | 2155 | prev->g.from = this_from; |
| 2084 | prev->to = this_to; | 2156 | prev->g.to = this_to; |
| 2085 | } | 2157 | } |
| 2086 | } | 2158 | } |
| 2087 | } | 2159 | } |
| 2088 | if (otfg->GlyphClass == OTF_GlyphClass0) | 2160 | if (otfg->glyph_id) |
| 2089 | base = mark = g; | 2161 | { |
| 2090 | else if (otfg->GlyphClass == OTF_GlyphClassMark) | 2162 | if (otfg->GlyphClass == OTF_GlyphClass0) |
| 2091 | mark = g; | 2163 | base = mark = g; |
| 2092 | else | 2164 | else if (otfg->GlyphClass == OTF_GlyphClassMark) |
| 2093 | base = g; | 2165 | mark = g; |
| 2166 | else | ||
| 2167 | base = g; | ||
| 2168 | g++, adjustment++; | ||
| 2169 | } | ||
| 2094 | } | 2170 | } |
| 2095 | } | 2171 | } |
| 2096 | else if (gpos_features) | 2172 | else if (gpos_features) |
| @@ -2114,8 +2190,8 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 2114 | tag = PACK_OTF_TAG (tag); | 2190 | tag = PACK_OTF_TAG (tag); |
| 2115 | for (j = otfg->f.index.from; j <= otfg->f.index.to; j++) | 2191 | for (j = otfg->f.index.from; j <= otfg->f.index.to; j++) |
| 2116 | { | 2192 | { |
| 2117 | MFLTGlyph *g = in->glyphs + (from + j); | 2193 | MFLTGlyphFT *g = in_glyphs + j; |
| 2118 | g->internal = (g->internal & ~0x1FFFFFFF) | tag; | 2194 | g->g.internal = (g->g.internal & ~0x1FFFFFFF) | tag; |
| 2119 | } | 2195 | } |
| 2120 | } | 2196 | } |
| 2121 | } | 2197 | } |
| @@ -2130,8 +2206,7 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 2130 | if (out->allocated < out->used + len) | 2206 | if (out->allocated < out->used + len) |
| 2131 | return -2; | 2207 | return -2; |
| 2132 | font->get_metrics (font, in, from, to); | 2208 | font->get_metrics (font, in, from, to); |
| 2133 | memcpy (out->glyphs + out->used, in->glyphs + from, | 2209 | memcpy (out->glyphs + out->used, in_glyphs, sizeof (MFLTGlyphFT) * len); |
| 2134 | sizeof (MFLTGlyph) * len); | ||
| 2135 | out->used += len; | 2210 | out->used += len; |
| 2136 | return to; | 2211 | return to; |
| 2137 | } | 2212 | } |
| @@ -2220,7 +2295,7 @@ ftfont_drive_otf (MFLTFont *font, MFLTOtfSpec *spec, MFLTGlyphString *in, | |||
| 2220 | } | 2295 | } |
| 2221 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; ) | 2296 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; ) |
| 2222 | { | 2297 | { |
| 2223 | MFLTGlyph *g; | 2298 | MFLTGlyphFT *g; |
| 2224 | int min_from, max_to; | 2299 | int min_from, max_to; |
| 2225 | int j; | 2300 | int j; |
| 2226 | 2301 | ||
| @@ -2278,7 +2353,7 @@ ftfont_drive_otf (MFLTFont *font, MFLTOtfSpec *spec, MFLTGlyphString *in, | |||
| 2278 | 2353 | ||
| 2279 | if (gpos_features) | 2354 | if (gpos_features) |
| 2280 | { | 2355 | { |
| 2281 | MFLTGlyph *base = NULL, *mark = NULL, *g; | 2356 | MFLTGlyphFT *base = NULL, *mark = NULL, *g; |
| 2282 | int x_ppem, y_ppem, x_scale, y_scale; | 2357 | int x_ppem, y_ppem, x_scale, y_scale; |
| 2283 | 2358 | ||
| 2284 | if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features) | 2359 | if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features) |
| @@ -2296,7 +2371,7 @@ ftfont_drive_otf (MFLTFont *font, MFLTOtfSpec *spec, MFLTGlyphString *in, | |||
| 2296 | for (i = 0, otfg = otf_gstring.glyphs, g = out->glyphs + gidx; | 2371 | for (i = 0, otfg = otf_gstring.glyphs, g = out->glyphs + gidx; |
| 2297 | i < otf_gstring.used; i++, otfg++, g++) | 2372 | i < otf_gstring.used; i++, otfg++, g++) |
| 2298 | { | 2373 | { |
| 2299 | MFLTGlyph *prev; | 2374 | MFLTGlyphFT *prev; |
| 2300 | 2375 | ||
| 2301 | if (! otfg->glyph_id) | 2376 | if (! otfg->glyph_id) |
| 2302 | continue; | 2377 | continue; |
| @@ -2425,6 +2500,7 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2425 | struct MFLTFontFT flt_font_ft; | 2500 | struct MFLTFontFT flt_font_ft; |
| 2426 | MFLT *flt = NULL; | 2501 | MFLT *flt = NULL; |
| 2427 | bool with_variation_selector = 0; | 2502 | bool with_variation_selector = 0; |
| 2503 | MFLTGlyphFT *glyphs; | ||
| 2428 | 2504 | ||
| 2429 | if (! m17n_flt_initialized) | 2505 | if (! m17n_flt_initialized) |
| 2430 | { | 2506 | { |
| @@ -2484,26 +2560,27 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2484 | 2560 | ||
| 2485 | if (gstring.allocated == 0) | 2561 | if (gstring.allocated == 0) |
| 2486 | { | 2562 | { |
| 2487 | gstring.glyph_size = sizeof (MFLTGlyph); | 2563 | gstring.glyph_size = sizeof (MFLTGlyphFT); |
| 2488 | gstring.glyphs = xnmalloc (len * 2, sizeof *gstring.glyphs); | 2564 | gstring.glyphs = xnmalloc (len * 2, sizeof (MFLTGlyphFT)); |
| 2489 | gstring.allocated = len * 2; | 2565 | gstring.allocated = len * 2; |
| 2490 | } | 2566 | } |
| 2491 | else if (gstring.allocated < len * 2) | 2567 | else if (gstring.allocated < len * 2) |
| 2492 | { | 2568 | { |
| 2493 | gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, | 2569 | gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, |
| 2494 | sizeof *gstring.glyphs); | 2570 | sizeof (MFLTGlyphFT)); |
| 2495 | gstring.allocated = len * 2; | 2571 | gstring.allocated = len * 2; |
| 2496 | } | 2572 | } |
| 2497 | memset (gstring.glyphs, 0, len * sizeof *gstring.glyphs); | 2573 | glyphs = (MFLTGlyphFT *) (gstring.glyphs); |
| 2574 | memset (glyphs, 0, len * sizeof (MFLTGlyphFT)); | ||
| 2498 | for (i = 0; i < len; i++) | 2575 | for (i = 0; i < len; i++) |
| 2499 | { | 2576 | { |
| 2500 | Lisp_Object g = LGSTRING_GLYPH (lgstring, i); | 2577 | Lisp_Object g = LGSTRING_GLYPH (lgstring, i); |
| 2501 | 2578 | ||
| 2502 | gstring.glyphs[i].c = LGLYPH_CHAR (g); | 2579 | glyphs[i].g.c = LGLYPH_CHAR (g); |
| 2503 | if (with_variation_selector) | 2580 | if (with_variation_selector) |
| 2504 | { | 2581 | { |
| 2505 | gstring.glyphs[i].code = LGLYPH_CODE (g); | 2582 | glyphs[i].g.code = LGLYPH_CODE (g); |
| 2506 | gstring.glyphs[i].encoded = 1; | 2583 | glyphs[i].g.encoded = 1; |
| 2507 | } | 2584 | } |
| 2508 | } | 2585 | } |
| 2509 | 2586 | ||
| @@ -2544,45 +2621,45 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2544 | if (INT_MAX / 2 < gstring.allocated) | 2621 | if (INT_MAX / 2 < gstring.allocated) |
| 2545 | memory_full (SIZE_MAX); | 2622 | memory_full (SIZE_MAX); |
| 2546 | gstring.glyphs = xnrealloc (gstring.glyphs, | 2623 | gstring.glyphs = xnrealloc (gstring.glyphs, |
| 2547 | gstring.allocated, 2 * sizeof (MFLTGlyph)); | 2624 | gstring.allocated, 2 * sizeof (MFLTGlyphFT)); |
| 2548 | gstring.allocated *= 2; | 2625 | gstring.allocated *= 2; |
| 2549 | } | 2626 | } |
| 2550 | if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) | 2627 | if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) |
| 2551 | return Qnil; | 2628 | return Qnil; |
| 2552 | for (i = 0; i < gstring.used; i++) | 2629 | for (i = 0; i < gstring.used; i++) |
| 2553 | { | 2630 | { |
| 2554 | MFLTGlyph *g = gstring.glyphs + i; | 2631 | MFLTGlyphFT *g = (MFLTGlyphFT *) (gstring.glyphs) + i; |
| 2555 | 2632 | ||
| 2556 | g->from = LGLYPH_FROM (LGSTRING_GLYPH (lgstring, g->from)); | 2633 | g->g.from = LGLYPH_FROM (LGSTRING_GLYPH (lgstring, g->g.from)); |
| 2557 | g->to = LGLYPH_TO (LGSTRING_GLYPH (lgstring, g->to)); | 2634 | g->g.to = LGLYPH_TO (LGSTRING_GLYPH (lgstring, g->g.to)); |
| 2558 | } | 2635 | } |
| 2559 | 2636 | ||
| 2560 | for (i = 0; i < gstring.used; i++) | 2637 | for (i = 0; i < gstring.used; i++) |
| 2561 | { | 2638 | { |
| 2562 | Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i); | 2639 | Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i); |
| 2563 | MFLTGlyph *g = gstring.glyphs + i; | 2640 | MFLTGlyphFT *g = (MFLTGlyphFT *) (gstring.glyphs) + i; |
| 2564 | 2641 | ||
| 2565 | if (NILP (lglyph)) | 2642 | if (NILP (lglyph)) |
| 2566 | { | 2643 | { |
| 2567 | lglyph = LGLYPH_NEW (); | 2644 | lglyph = LGLYPH_NEW (); |
| 2568 | LGSTRING_SET_GLYPH (lgstring, i, lglyph); | 2645 | LGSTRING_SET_GLYPH (lgstring, i, lglyph); |
| 2569 | } | 2646 | } |
| 2570 | LGLYPH_SET_FROM (lglyph, g->from); | 2647 | LGLYPH_SET_FROM (lglyph, g->g.from); |
| 2571 | LGLYPH_SET_TO (lglyph, g->to); | 2648 | LGLYPH_SET_TO (lglyph, g->g.to); |
| 2572 | LGLYPH_SET_CHAR (lglyph, g->c); | 2649 | LGLYPH_SET_CHAR (lglyph, g->g.c); |
| 2573 | LGLYPH_SET_CODE (lglyph, g->code); | 2650 | LGLYPH_SET_CODE (lglyph, g->g.code); |
| 2574 | LGLYPH_SET_WIDTH (lglyph, g->xadv >> 6); | 2651 | LGLYPH_SET_WIDTH (lglyph, g->g.xadv >> 6); |
| 2575 | LGLYPH_SET_LBEARING (lglyph, g->lbearing >> 6); | 2652 | LGLYPH_SET_LBEARING (lglyph, g->g.lbearing >> 6); |
| 2576 | LGLYPH_SET_RBEARING (lglyph, g->rbearing >> 6); | 2653 | LGLYPH_SET_RBEARING (lglyph, g->g.rbearing >> 6); |
| 2577 | LGLYPH_SET_ASCENT (lglyph, g->ascent >> 6); | 2654 | LGLYPH_SET_ASCENT (lglyph, g->g.ascent >> 6); |
| 2578 | LGLYPH_SET_DESCENT (lglyph, g->descent >> 6); | 2655 | LGLYPH_SET_DESCENT (lglyph, g->g.descent >> 6); |
| 2579 | if (g->adjusted) | 2656 | if (g->g.adjusted) |
| 2580 | { | 2657 | { |
| 2581 | Lisp_Object vec = make_uninit_vector (3); | 2658 | Lisp_Object vec = make_uninit_vector (3); |
| 2582 | 2659 | ||
| 2583 | ASET (vec, 0, make_number (g->xoff >> 6)); | 2660 | ASET (vec, 0, make_number (g->g.xoff >> 6)); |
| 2584 | ASET (vec, 1, make_number (g->yoff >> 6)); | 2661 | ASET (vec, 1, make_number (g->g.yoff >> 6)); |
| 2585 | ASET (vec, 2, make_number (g->xadv >> 6)); | 2662 | ASET (vec, 2, make_number (g->g.xadv >> 6)); |
| 2586 | LGLYPH_SET_ADJUSTMENT (lglyph, vec); | 2663 | LGLYPH_SET_ADJUSTMENT (lglyph, vec); |
| 2587 | } | 2664 | } |
| 2588 | } | 2665 | } |