$42 GRAYBYTE WORDPRESS FILE MANAGER $87

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.217.254 | ADMIN IP 216.73.216.23
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/libicu/usr/share/doc/alt-libicu-devel/samples/layout/

HOME
Current File : /opt/alt/libicu/usr/share/doc/alt-libicu-devel/samples/layout//GnomeFontInstance.cpp
/*
 *******************************************************************************
 *
 *   © 2016 and later: Unicode, Inc. and others.
 *   License & terms of use: http://www.unicode.org/copyright.html#License
 *
 *******************************************************************************
 *******************************************************************************
 *
 *   Copyright (C) 1999-2007, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  GnomeFontInstance.cpp
 *
 *   created on: 08/30/2001
 *   created by: Eric R. Mader
 */

#include <gnome.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include FT_RENDER_H
#include FT_TRUETYPE_TABLES_H
#include <cairo.h>
#include <cairo-ft.h>

#include "layout/LETypes.h"
#include "layout/LESwaps.h"

#include "GnomeFontInstance.h"
#include "sfnt.h"
#include "cmaps.h"

GnomeSurface::GnomeSurface(GtkWidget *theWidget)
    : fWidget(theWidget)
{
    fCairo = gdk_cairo_create(fWidget->window);
}

GnomeSurface::~GnomeSurface()
{
    cairo_destroy(fCairo);
}

void GnomeSurface::drawGlyphs(const LEFontInstance *font, const LEGlyphID *glyphs, le_int32 count,
                              const float *positions, le_int32 x, le_int32 y, le_int32 /*width*/, le_int32 /*height*/)
{
    GnomeFontInstance *gFont = (GnomeFontInstance *) font;
    
    gFont->rasterizeGlyphs(fCairo, glyphs, count, positions, x, y);
}

GnomeFontInstance::GnomeFontInstance(FT_Library engine, const char *fontPathName, le_int16 pointSize, LEErrorCode &status)
    : FontTableCache(), fPointSize(pointSize), fUnitsPerEM(0), fAscent(0), fDescent(0), fLeading(0),
      fDeviceScaleX(1), fDeviceScaleY(1), fMapper(NULL)
{
    FT_Error error;

    fFace      = NULL;
    fCairoFace = NULL;

    error = FT_New_Face(engine, fontPathName, 0, &fFace);

    if (error != 0) {
        printf("OOPS! Got error code %d\n", error);
        status = LE_FONT_FILE_NOT_FOUND_ERROR;
        return;
    }

    // FIXME: what about the display resolution?
    fDeviceScaleX = ((float) 96) / 72;
    fDeviceScaleY = ((float) 96) / 72;

    error = FT_Set_Char_Size(fFace, 0, pointSize << 6, 92, 92);
    
    fCairoFace = cairo_ft_font_face_create_for_ft_face(fFace, 0);

    fUnitsPerEM = fFace->units_per_EM;

    fAscent  = (le_int32) (yUnitsToPoints(fFace->ascender) * fDeviceScaleY);
    fDescent = (le_int32) -(yUnitsToPoints(fFace->descender) * fDeviceScaleY);
    fLeading = (le_int32) (yUnitsToPoints(fFace->height) * fDeviceScaleY) - fAscent - fDescent;

    // printf("Face = %s, unitsPerEM = %d, ascent = %d, descent = %d\n", fontPathName, fUnitsPerEM, fAscent, fDescent);

    if (error != 0) {
        status = LE_MEMORY_ALLOCATION_ERROR;
        return;
    }

    status = initMapper();
}

GnomeFontInstance::~GnomeFontInstance()
{
    cairo_font_face_destroy(fCairoFace);
    
    if (fFace != NULL) {
        FT_Done_Face(fFace);
    }
}

LEErrorCode GnomeFontInstance::initMapper()
{
    LETag cmapTag = LE_CMAP_TABLE_TAG;
    const CMAPTable *cmap = (const CMAPTable *) readFontTable(cmapTag);

    if (cmap == NULL) {
        return LE_MISSING_FONT_TABLE_ERROR;
    }

    fMapper = CMAPMapper::createUnicodeMapper(cmap);

    if (fMapper == NULL) {
        return LE_MISSING_FONT_TABLE_ERROR;
    }

    return LE_NO_ERROR;
}

const void *GnomeFontInstance::getFontTable(LETag tableTag) const
{
    return FontTableCache::find(tableTag);
}

const void *GnomeFontInstance::readFontTable(LETag tableTag) const
{
    FT_ULong len = 0;
    FT_Byte *result = NULL;

    FT_Load_Sfnt_Table(fFace, tableTag, 0, NULL, &len);

    if (len > 0) {
        result = LE_NEW_ARRAY(FT_Byte, len);
        FT_Load_Sfnt_Table(fFace, tableTag, 0, result, &len);
    }

    return result;
}

void GnomeFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
{
    advance.fX = 0;
    advance.fY = 0;

    if (glyph >= 0xFFFE) {
        return;
    }

    FT_Error error;

    error = FT_Load_Glyph(fFace, glyph, FT_LOAD_DEFAULT);

    if (error != 0) {
        return;
    }

    advance.fX = fFace->glyph->metrics.horiAdvance >> 6;
    return;
}

le_bool GnomeFontInstance::getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const
{
    FT_Error error;

    error = FT_Load_Glyph(fFace, glyph, FT_LOAD_DEFAULT);

    if (error != 0) {
        return FALSE;
    }

    if (pointNumber >= fFace->glyph->outline.n_points) {
        return FALSE;
    }

    point.fX = fFace->glyph->outline.points[pointNumber].x >> 6;
    point.fY = fFace->glyph->outline.points[pointNumber].y >> 6;

    return TRUE;
}

void GnomeFontInstance::rasterizeGlyphs(cairo_t *cairo, const LEGlyphID *glyphs, le_int32 glyphCount, const float *positions,
                                        le_int32 x, le_int32 y) const
{
    cairo_glyph_t *glyph_t = LE_NEW_ARRAY(cairo_glyph_t, glyphCount);
    le_int32 in, out;
    
    for (in = 0, out = 0; in < glyphCount; in += 1) {
        TTGlyphID glyph = LE_GET_GLYPH(glyphs[in]);
        
        if (glyph < 0xFFFE) {
            glyph_t[out].index = glyph;
            glyph_t[out].x     = x + positions[in*2];
            glyph_t[out].y     = y + positions[in*2 + 1];
            
            out += 1;
        }
    }
    
    cairo_set_font_face(cairo, fCairoFace);
    cairo_set_font_size(cairo, getXPixelsPerEm() * getScaleFactorX());
    cairo_show_glyphs(cairo, glyph_t, out);
    
    LE_DELETE_ARRAY(glyph_t);
}


Current_dir [ NOT WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
3 Mar 2024 10.40 PM
root / root
0755
FontMap.GDI
0.416 KB
17 Apr 2019 7.42 PM
root / root
0644
FontMap.Gnome
0.383 KB
17 Apr 2019 7.42 PM
root / root
0644
FontMap.cpp
7.341 KB
17 Apr 2019 7.42 PM
root / root
0644
FontMap.h
1.843 KB
17 Apr 2019 7.42 PM
root / root
0644
FontTableCache.cpp
2.37 KB
17 Apr 2019 7.42 PM
root / root
0644
FontTableCache.h
1.063 KB
17 Apr 2019 7.42 PM
root / root
0644
GDIFontInstance.cpp
9.596 KB
17 Apr 2019 7.42 PM
root / root
0644
GDIFontInstance.h
3.602 KB
17 Apr 2019 7.42 PM
root / root
0644
GDIFontMap.cpp
1.324 KB
17 Apr 2019 7.42 PM
root / root
0644
GDIFontMap.h
1.232 KB
17 Apr 2019 7.42 PM
root / root
0644
GDIGUISupport.cpp
0.842 KB
17 Apr 2019 7.42 PM
root / root
0644
GDIGUISupport.h
0.927 KB
17 Apr 2019 7.42 PM
root / root
0644
GUISupport.h
0.869 KB
17 Apr 2019 7.42 PM
root / root
0644
GnomeFontInstance.cpp
5.427 KB
17 Apr 2019 7.42 PM
root / root
0644
GnomeFontInstance.h
3.789 KB
17 Apr 2019 7.42 PM
root / root
0644
GnomeFontMap.cpp
1.394 KB
17 Apr 2019 7.42 PM
root / root
0644
GnomeFontMap.h
1.211 KB
17 Apr 2019 7.42 PM
root / root
0644
GnomeGUISupport.cpp
1.049 KB
17 Apr 2019 7.42 PM
root / root
0644
GnomeGUISupport.h
0.938 KB
17 Apr 2019 7.42 PM
root / root
0644
LayoutSample.rc
3.369 KB
17 Apr 2019 7.42 PM
root / root
0644
Makefile
2.918 KB
7 Nov 2019 6.56 AM
root / root
0644
Makefile.in
2.921 KB
17 Apr 2019 7.42 PM
root / root
0644
RenderingSurface.h
1.093 KB
17 Apr 2019 7.42 PM
root / root
0644
Sample.txt
1.657 KB
17 Apr 2019 7.42 PM
root / root
0644
ScriptCompositeFontInstance.cpp
3.197 KB
17 Apr 2019 7.42 PM
root / root
0644
ScriptCompositeFontInstance.h
6.154 KB
17 Apr 2019 7.42 PM
root / root
0644
Surface.cpp
0.871 KB
17 Apr 2019 7.42 PM
root / root
0644
Surface.h
0.507 KB
17 Apr 2019 7.42 PM
root / root
0644
UnicodeReader.cpp
4.104 KB
17 Apr 2019 7.42 PM
root / root
0644
UnicodeReader.h
0.976 KB
17 Apr 2019 7.42 PM
root / root
0644
arraymem.h
0.631 KB
17 Apr 2019 7.42 PM
root / root
0644
cgnomelayout.c
8.445 KB
17 Apr 2019 7.42 PM
root / root
0644
clayout.c
9.824 KB
17 Apr 2019 7.42 PM
root / root
0644
cmaps.cpp
5.301 KB
17 Apr 2019 7.42 PM
root / root
0644
cmaps.h
2.057 KB
17 Apr 2019 7.42 PM
root / root
0644
gdiglue.cpp
1.667 KB
17 Apr 2019 7.42 PM
root / root
0644
gdiglue.h
0.96 KB
17 Apr 2019 7.42 PM
root / root
0644
gnomeglue.cpp
1.643 KB
17 Apr 2019 7.42 PM
root / root
0644
gnomeglue.h
0.963 KB
17 Apr 2019 7.42 PM
root / root
0644
gnomelayout.cpp
8.497 KB
17 Apr 2019 7.42 PM
root / root
0644
gsupport.h
0.361 KB
17 Apr 2019 7.42 PM
root / root
0644
layout.cpp
9.797 KB
17 Apr 2019 7.42 PM
root / root
0644
layout.sln
1.174 KB
17 Apr 2019 7.42 PM
root / root
0644
layout.vcxproj
13.154 KB
17 Apr 2019 7.42 PM
root / root
0644
layout.vcxproj.filters
3.059 KB
17 Apr 2019 7.42 PM
root / root
0644
paragraph.cpp
7.583 KB
17 Apr 2019 7.42 PM
root / root
0644
paragraph.h
2.18 KB
17 Apr 2019 7.42 PM
root / root
0644
pflow.c
9.268 KB
17 Apr 2019 7.42 PM
root / root
0644
pflow.h
0.918 KB
17 Apr 2019 7.42 PM
root / root
0644
readme.html
7.324 KB
17 Apr 2019 7.42 PM
root / root
0644
resource.h
0.886 KB
17 Apr 2019 7.42 PM
root / root
0644
rsurface.cpp
0.695 KB
17 Apr 2019 7.42 PM
root / root
0644
rsurface.h
0.516 KB
17 Apr 2019 7.42 PM
root / root
0644
sfnt.h
4.903 KB
17 Apr 2019 7.42 PM
root / root
0644
ucreader.cpp
0.497 KB
17 Apr 2019 7.42 PM
root / root
0644
ucreader.h
0.412 KB
17 Apr 2019 7.42 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF