Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
/* Copyright (C) 2009 The PARI group.
2
3
This file is part of the PARI/GP package.
4
5
PARI/GP is free software; you can redistribute it and/or modify it under the
6
terms of the GNU General Public License as published by the Free Software
7
Foundation; either version 2 of the License, or (at your option) any later
8
version. It is distributed in the hope that it will be useful, but WITHOUT
9
ANY WARRANTY WHATSOEVER.
10
11
Check the License for details. You should have received a copy of it, along
12
with the package; see the file 'COPYING'. If not, write to the Free Software
13
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
14
15
/* Written by Vasili Burdo */
16
17
#include "../systems/mingw/pwinver.h"
18
#include <windows.h>
19
#include <time.h>
20
#include "pari.h"
21
#include "rect.h"
22
23
static void SetForeground(void *data, long col)
24
{
25
HPEN hOldPen;
26
int r, g, b; long_to_rgb(col, &r, &g, &b);
27
SetDCPenColor((HDC)data,RGB(r,g,b));
28
hOldPen = SelectObject((HDC)data, CreatePen(PS_SOLID, 1, RGB(r,g,b)));
29
if( hOldPen ) DeleteObject(hOldPen);
30
}
31
32
static void DrawPoint(void *data, long x, long y)
33
{
34
Ellipse((HDC)data,x-1,y-1,x+1,y+1);
35
}
36
37
static void DrawLine(void *data, long x1, long y1, long x2, long y2)
38
{
39
MoveToEx((HDC)data, x1, y1, NULL);
40
LineTo((HDC)data,x2,y2);
41
}
42
43
static void DrawRectangle(void *data, long x, long y, long w, long h)
44
{
45
DrawLine(data, x,y,x+w,y);
46
DrawLine(data, x,y,x,y+h);
47
DrawLine(data, x+w,y,x+w,y+h);
48
DrawLine(data, x,y+h,x+w,y+h);
49
}
50
51
static void FillRectangle(void *data, long x, long y, long w, long h)
52
{
53
RECT rc;
54
COLORREF color;
55
HBRUSH brush;
56
rc.left = x; rc.right = x+w;
57
rc.top = y; rc.bottom = y+h;
58
color = GetDCPenColor((HDC) data);
59
brush = CreateSolidBrush(color);
60
FillRect((HDC)data, &rc, brush);
61
DeleteObject(brush);
62
}
63
64
static void DrawPoints(void *data, long nb, struct plot_points *p)
65
{
66
long i;
67
for (i=0; i<nb; ++i)
68
DrawPoint(data,p[i].x,p[i].y);
69
}
70
71
static void DrawLines(void *data, long nb, struct plot_points *p)
72
{
73
long i;
74
MoveToEx((HDC)data, p[0].x, p[0].y, NULL);
75
for(i=1; i<nb; ++i)
76
LineTo((HDC)data,p[i].x,p[i].y);
77
}
78
79
static void DrawString(void *data, long x, long y, char *text, long numtext)
80
{
81
TextOut((HDC)data, x, y, text, numtext);
82
}
83
84
static void
85
draw(PARI_plot *T, GEN w, GEN x, GEN y)
86
{
87
char tmppath[MAX_PATH], fname[2 * MAX_PATH];
88
struct plot_eng plotWin32;
89
HDC hEmf;
90
int r, g, b;
91
92
GetTempPath(sizeof(tmppath), tmppath);
93
sprintf(fname, "%s\\gp-ploth-%lx.emf", tmppath, time(NULL)/(24*60*60)*1000+GetTickCount());
94
95
hEmf = CreateEnhMetaFile(GetDC(NULL), fname, NULL, NULL);
96
SetMapMode(hEmf, MM_TEXT);
97
SelectObject(hEmf, GetStockObject(DEFAULT_GUI_FONT));
98
color_to_rgb(gel(GP_DATA->colormap,1), &r,&g,&b);
99
SetBkColor(hEmf, RGB(r,g,b));
100
SetBkMode(hEmf, OPAQUE);
101
102
plotWin32.sc=&SetForeground;
103
plotWin32.pt=&DrawPoint;
104
plotWin32.ln=&DrawLine;
105
plotWin32.bx=&DrawRectangle;
106
plotWin32.fb=&FillRectangle;
107
plotWin32.mp=&DrawPoints;
108
plotWin32.ml=&DrawLines;
109
plotWin32.st=&DrawString;
110
plotWin32.pl=T;
111
plotWin32.data=(void*)hEmf;
112
113
gen_draw(&plotWin32, w, x, y, 1, 1);
114
DeleteEnhMetaFile(CloseEnhMetaFile(hEmf));
115
116
ShellExecute(NULL,NULL,fname,NULL,NULL,SW_SHOWDEFAULT);
117
}
118
119
INLINE void
120
gp_get_display_sizes(long *dwidth, long *dheight, long *fwidth, long *fheight)
121
{
122
HDC hdc;
123
TEXTMETRIC tm;
124
125
*dwidth = GetSystemMetrics(SM_CXSCREEN);
126
*dheight = GetSystemMetrics(SM_CYSCREEN);
127
128
hdc = GetDC(0);
129
SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));
130
GetTextMetrics(hdc, &tm);
131
ReleaseDC(0,hdc);
132
133
*fwidth = tm.tmAveCharWidth;
134
*fheight = tm.tmHeight;
135
}
136
137
void
138
gp_get_plot(PARI_plot *T)
139
{
140
gp_get_plot_generic(T,gp_get_display_sizes);
141
T->draw = &draw;
142
}
143
144