Ejemplo n.º 1
0
void print_vec3(vec3 *v) {
  double x = fixed_to_double(v->x),
    y = fixed_to_double(v->y),
    z = fixed_to_double(v->z);

  printf("(%f, %f, %f)\n", x, y, z);
}
Ejemplo n.º 2
0
/* Apply track gain and polarity inversion
 */
static void volume_get_clip_range(fft_fixed gain, sample_t clip_range[2]) {
	if (gain > FIXED_ONE) {
		clip_range[0] = (sample_t)(SAMPLE_MAX / fixed_to_double(gain));
		clip_range[1] = (sample_t)(SAMPLE_MIN / fixed_to_double(gain));
	}
	else {
		clip_range[0] = SAMPLE_MAX;
		clip_range[1] = SAMPLE_MIN;
	}
}
Ejemplo n.º 3
0
Archivo: mat.c Proyecto: tuttlem/freak
void mat44_print(mat44 *m) {
  int o = 0, y = 0;
  double a, b, c, d;

  for (y = 0; y < 4; y ++) {
    a = fixed_to_double(m->m[o]);
    b = fixed_to_double(m->m[o + 1]);
    c = fixed_to_double(m->m[o + 2]);
    d = fixed_to_double(m->m[o + 3]);
    
    printf("[ %f, %f, %f, %f ]\n", a, b, c, d);

    o += 4;
  }

}
Ejemplo n.º 4
0
OpBpath* WindowsSVGFont::GetGlyphOutline(uni_char uc)
{
    DWORD err = 0;
    OpBpath* path = NULL;
    WindowsOpFont* wopfont = (WindowsOpFont*)m_font;

    HDC fonthdc = WindowsOpFont::fonthdc;
    void * oldGdiObj = NULL;

    if (WindowsOpFont::font_on_dc != wopfont)
    {
        oldGdiObj = SelectObject(fonthdc, wopfont->fnt);
        WindowsOpFont::font_on_dc = wopfont;
    }

    GLYPHMETRICS metrics;
    MAT2 matrix;
    UINT8 buffer[buffer_size];

    memset(&matrix, 0, sizeof(matrix));
    matrix.eM11.value = 1;
    matrix.eM22.value = 1;

    err = ::GetGlyphOutline( fonthdc, uc, GGO_NATIVE, &metrics, buffer_size, buffer, &matrix);
    if(err != GDI_ERROR)
    {
        TTPOLYGONHEADER* ph = (TTPOLYGONHEADER*)buffer;
        INT32 phpos = 0;

        path = new OpBpath();
        if(!path)
            return NULL;

        while(ph < (TTPOLYGONHEADER*)&buffer[err])
        {
            path->MoveTo(fixed_to_double(ph->pfxStart.x), fixed_to_double(ph->pfxStart.y), FALSE);

            INT32 pcpos = phpos + sizeof(TTPOLYGONHEADER);
            INT32 endpos = phpos + ph->cb;
            TTPOLYCURVE* pc = (TTPOLYCURVE*) &buffer[pcpos];
            while(pc < (TTPOLYCURVE*) &buffer[endpos])
            {
                if(pc->wType == TT_PRIM_LINE)
                {
                    // straight line
                    for(int i = 0; i < pc->cpfx; i++)
                    {
                        path->LineTo(fixed_to_double(pc->apfx[i].x), fixed_to_double(pc->apfx[i].y), FALSE);
                    }
                }
                else if(pc->wType == TT_PRIM_QSPLINE)
                {
                    // quadratic spline
                    for(int i = 0; i < pc->cpfx-1; i++)
                    {
                        POINTFX* b = &pc->apfx[i];
                        POINTFX* c = &pc->apfx[i+1];
                        SVGCoordinatePair ep;

                        if(i < pc->cpfx - 2)
                        {
                            ep.x = (fixed_to_double(b->x) + fixed_to_double(c->x)) / 2;
                            ep.y = (fixed_to_double(b->y) + fixed_to_double(c->y)) / 2;
                        }
                        else
                        {
                            ep.x = fixed_to_double(c->x);
                            ep.y = fixed_to_double(c->y);
                        }

                        path->QuadraticCurveTo(fixed_to_double(b->x), fixed_to_double(b->y),
                                               ep.x, ep.y,
                                               FALSE, FALSE);
                    }
                }
                else if(pc->wType == TT_PRIM_CSPLINE)
                {
                    // cubic spline
                    for(int i = 0; i < pc->cpfx-2; i++)
                    {
                        POINTFX* cp1 = &pc->apfx[i];
                        POINTFX* cp2 = &pc->apfx[i+1];
                        POINTFX* endp = &pc->apfx[i+2];
                        path->CubicCurveTo(fixed_to_double(cp1->x), fixed_to_double(cp1->y),
                                           fixed_to_double(cp2->x), fixed_to_double(cp2->y),
                                           fixed_to_double(endp->x), fixed_to_double(endp->y),
                                           FALSE, FALSE);
                    }
                }

                pcpos += 2 * sizeof(WORD) + sizeof(POINTFX) * pc->cpfx;
                pc = (TTPOLYCURVE*) &buffer[pcpos];
            }

            path->Close();

            phpos += ph->cb;
            ph = (TTPOLYGONHEADER*)&buffer[phpos];
        }
    }

    if(oldGdiObj != NULL)
        SelectObject(fonthdc, oldGdiObj);

    return path;
}
Ejemplo n.º 5
0
/***********************************************************************
 *		wglUseFontOutlines_common
 */
static BOOL wglUseFontOutlines_common(HDC hdc,
                                      DWORD first,
                                      DWORD count,
                                      DWORD listBase,
                                      FLOAT deviation,
                                      FLOAT extrusion,
                                      int format,
                                      LPGLYPHMETRICSFLOAT lpgmf,
                                      BOOL unicode)
{
    UINT glyph;
    const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}};
    GLUtesselator *tess;
    LOGFONTW lf;
    HFONT old_font, unscaled_font;
    UINT em_size = 1024;
    RECT rc;

    TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
          listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");

    if (!load_libglu())
    {
        ERR("libGLU is required for this function but isn't loaded\n");
        return FALSE;
    }

    ENTER_GL();
    tess = pgluNewTess();
    if(tess)
    {
        pgluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
        pgluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
        pgluTessCallback(tess, GLU_TESS_END, tess_callback_end);
    }
    LEAVE_GL();

    if(!tess) return FALSE;

    GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
    rc.left = rc.right = rc.bottom = 0;
    rc.top = em_size;
    DPtoLP(hdc, (POINT*)&rc, 2);
    lf.lfHeight = -abs(rc.top - rc.bottom);
    lf.lfOrientation = lf.lfEscapement = 0;
    unscaled_font = CreateFontIndirectW(&lf);
    old_font = SelectObject(hdc, unscaled_font);

    for (glyph = first; glyph < first + count; glyph++)
    {
        DWORD needed;
        GLYPHMETRICS gm;
        BYTE *buf;
        TTPOLYGONHEADER *pph;
        TTPOLYCURVE *ppc;
        GLdouble *vertices;

        if(unicode)
            needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
        else
            needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);

        if(needed == GDI_ERROR)
            goto error;

        buf = HeapAlloc(GetProcessHeap(), 0, needed);
        vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble));

        if(unicode)
            GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
        else
            GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);

        TRACE("glyph %d\n", glyph);

        if(lpgmf)
        {
            lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
            lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
            lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
            lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
            lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
            lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;

            TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
                  lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY); 
            lpgmf++;
        }

	ENTER_GL();
	glNewList(listBase++, GL_COMPILE);
        pgluTessBeginPolygon(tess, NULL);

        pph = (TTPOLYGONHEADER*)buf;
        while((BYTE*)pph < buf + needed)
        {
            TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);

            pgluTessBeginContour(tess);

            fixed_to_double(pph->pfxStart, em_size, vertices);
            pgluTessVertex(tess, vertices, vertices);
            vertices += 3;

            ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
            while((char*)ppc < (char*)pph + pph->cb)
            {
                int i;

                switch(ppc->wType) {
                case TT_PRIM_LINE:
                    for(i = 0; i < ppc->cpfx; i++)
                    {
                        TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value);
                        fixed_to_double(ppc->apfx[i], em_size, vertices); 
                        pgluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                    }
                    break;

                case TT_PRIM_QSPLINE:
                    for(i = 0; i < ppc->cpfx/2; i++)
                    {
                        /* FIXME just connecting the control points for now */
                        TRACE("\t\tcurve  %d,%d %d,%d\n",
                              ppc->apfx[i * 2].x.value,     ppc->apfx[i * 3].y.value,
                              ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value);
                        fixed_to_double(ppc->apfx[i * 2], em_size, vertices); 
                        pgluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                        fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices); 
                        pgluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                    }
                    break;
                default:
                    ERR("\t\tcurve type = %d\n", ppc->wType);
                    pgluTessEndContour(tess);
                    goto error_in_list;
                }

                ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
                                     (ppc->cpfx - 1) * sizeof(POINTFX));
            }
            pgluTessEndContour(tess);
            pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
        }

error_in_list:
        pgluTessEndPolygon(tess);
        glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
        glEndList();
        LEAVE_GL();
        HeapFree(GetProcessHeap(), 0, buf);
        HeapFree(GetProcessHeap(), 0, vertices);
    }

 error:
    DeleteObject(SelectObject(hdc, old_font));
    pgluDeleteTess(tess);
    return TRUE;

}