Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* Copyright (C) 2009 The PARI group.12This file is part of the PARI/GP package.34PARI/GP is free software; you can redistribute it and/or modify it under the5terms of the GNU General Public License as published by the Free Software6Foundation; either version 2 of the License, or (at your option) any later7version. It is distributed in the hope that it will be useful, but WITHOUT8ANY WARRANTY WHATSOEVER.910Check the License for details. You should have received a copy of it, along11with the package; see the file 'COPYING'. If not, write to the Free Software12Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1314/* Written by Vasili Burdo */1516#include "../systems/mingw/pwinver.h"17#include <windows.h>18#include <time.h>19#include "pari.h"20#include "rect.h"2122static void SetForeground(void *data, long col)23{24HPEN hOldPen;25int r, g, b; long_to_rgb(col, &r, &g, &b);26SetDCPenColor((HDC)data,RGB(r,g,b));27hOldPen = SelectObject((HDC)data, CreatePen(PS_SOLID, 1, RGB(r,g,b)));28if( hOldPen ) DeleteObject(hOldPen);29}3031static void DrawPoint(void *data, long x, long y)32{33Ellipse((HDC)data,x-1,y-1,x+1,y+1);34}3536static void DrawLine(void *data, long x1, long y1, long x2, long y2)37{38MoveToEx((HDC)data, x1, y1, NULL);39LineTo((HDC)data,x2,y2);40}4142static void DrawRectangle(void *data, long x, long y, long w, long h)43{44DrawLine(data, x,y,x+w,y);45DrawLine(data, x,y,x,y+h);46DrawLine(data, x+w,y,x+w,y+h);47DrawLine(data, x,y+h,x+w,y+h);48}4950static void FillRectangle(void *data, long x, long y, long w, long h)51{52RECT rc;53COLORREF color;54HBRUSH brush;55rc.left = x; rc.right = x+w;56rc.top = y; rc.bottom = y+h;57color = GetDCPenColor((HDC) data);58brush = CreateSolidBrush(color);59FillRect((HDC)data, &rc, brush);60DeleteObject(brush);61}6263static void DrawPoints(void *data, long nb, struct plot_points *p)64{65long i;66for (i=0; i<nb; ++i)67DrawPoint(data,p[i].x,p[i].y);68}6970static void DrawLines(void *data, long nb, struct plot_points *p)71{72long i;73MoveToEx((HDC)data, p[0].x, p[0].y, NULL);74for(i=1; i<nb; ++i)75LineTo((HDC)data,p[i].x,p[i].y);76}7778static void DrawString(void *data, long x, long y, char *text, long numtext)79{80TextOut((HDC)data, x, y, text, numtext);81}8283static void84draw(PARI_plot *T, GEN w, GEN x, GEN y)85{86char tmppath[MAX_PATH], fname[2 * MAX_PATH];87struct plot_eng plotWin32;88HDC hEmf;89int r, g, b;9091GetTempPath(sizeof(tmppath), tmppath);92sprintf(fname, "%s\\gp-ploth-%lx.emf", tmppath, time(NULL)/(24*60*60)*1000+GetTickCount());9394hEmf = CreateEnhMetaFile(GetDC(NULL), fname, NULL, NULL);95SetMapMode(hEmf, MM_TEXT);96SelectObject(hEmf, GetStockObject(DEFAULT_GUI_FONT));97color_to_rgb(gel(GP_DATA->colormap,1), &r,&g,&b);98SetBkColor(hEmf, RGB(r,g,b));99SetBkMode(hEmf, OPAQUE);100101plotWin32.sc=&SetForeground;102plotWin32.pt=&DrawPoint;103plotWin32.ln=&DrawLine;104plotWin32.bx=&DrawRectangle;105plotWin32.fb=&FillRectangle;106plotWin32.mp=&DrawPoints;107plotWin32.ml=&DrawLines;108plotWin32.st=&DrawString;109plotWin32.pl=T;110plotWin32.data=(void*)hEmf;111112gen_draw(&plotWin32, w, x, y, 1, 1);113DeleteEnhMetaFile(CloseEnhMetaFile(hEmf));114115ShellExecute(NULL,NULL,fname,NULL,NULL,SW_SHOWDEFAULT);116}117118INLINE void119gp_get_display_sizes(long *dwidth, long *dheight, long *fwidth, long *fheight)120{121HDC hdc;122TEXTMETRIC tm;123124*dwidth = GetSystemMetrics(SM_CXSCREEN);125*dheight = GetSystemMetrics(SM_CYSCREEN);126127hdc = GetDC(0);128SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));129GetTextMetrics(hdc, &tm);130ReleaseDC(0,hdc);131132*fwidth = tm.tmAveCharWidth;133*fheight = tm.tmHeight;134}135136void137gp_get_plot(PARI_plot *T)138{139gp_get_plot_generic(T,gp_get_display_sizes);140T->draw = &draw;141}142143144