-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcanvas.asp
More file actions
1424 lines (1173 loc) · 41.2 KB
/
Copy pathcanvas.asp
File metadata and controls
1424 lines (1173 loc) · 41.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<%
' ASPCanvas 2.0.2, the revenge
' The object of this version is a complete overhaul of the backend image map
' by converting it all to ADO streams. This should yield a speed increase of
' around 15x the previous version.
' This version will also be a lot trimmer than the earlier version. A lot of
' the unused stuff has been removed.
'
' Additions should include:
' Barcode production
' OCR-A OCR-B font
' Any other graphical drawing application I can think of.
Public Const PI = 3.14159265 ' Roughly
Class Canvas
Public GlobalColourTable()
Public BackgroundColourIndex
Public ForegroundColourIndex
Public TransparentColourIndex
Public UseTransparency
Public Comment
Public ErrorsToIISLog
Public ErrorsToResponse
Public ErrorsHalt
Public ErrorsToImage
Public BMPWarnings
Private m_objImage
Private m_lWidth
Private m_lHeight
Private m_lPow
Private m_lMask
public property get Version()
Version = "2.0.2"
end property
' The pixels are now ZERO based. All of a sudden, everything just got easier.
' Hooray for streams!
Public Property Let Pixel(ByVal lX,ByVal lY,ByVal lValue)
if (lX < m_lWidth - 1 And lX >= 0) And (lY < m_lHeight - 1And lY >= 0) then
m_objImage.Position = (CLng(lY) * m_lWidth) + CLng(lX)
m_objImage.WriteText Chr(lValue)
end if
End Property
Public Property Get Pixel(ByVal lX,ByVal lY)
if (lX < m_lWidth - 1 And lX >= 0) And (lY < m_lHeight - 1 And lY >= 0) then
m_objImage.Position = (CLng(lY) * m_lWidth) + CLng(lX)
Pixel = Asc(m_objImage.ReadText(1))
else
Pixel = 0
end if
End Property
' Internal fast pixel read and write, no bounds checking!
Private Property Let FastPixel(ByVal lX,ByVal lY,ByVal lValue)
m_objImage.Position = (CLng(lY) * m_lWidth) + CLng(lX)
m_objImage.WriteText Chr(lValue)
End Property
Private Property Get FastPixel(ByVal lX,ByVal lY)
m_objImage.Position = (CLng(lY) * m_lWidth) + CLng(lX)
FastPixel = Asc(m_objImage.ReadText(1))
End Property
Public Property Get Width()
Width = m_lWidth
End Property
Public Property Get Height()
Height = m_lHeight
End Property
' Replace() - REALLY REALLY SLOW!
Public Sub Replace(ByVal lOldColour,ByVal lNewColour)
Dim sOld, sNew
m_objImage.Position = 0
sOld = Chr(lOldColour)
sNew = Chr(lNewColour)
while not m_objImage.EOS
if m_objImage.ReadText(1) = sOld then
m_objImage.Position = m_objImage.Position - 1
m_objImage.WriteText sNew
end if
wend
End Sub
' Duplicate part of the image. Much, much faster...
Public Sub Copy(ByVal lX1,ByVal lY1,ByVal lX2,ByVal lY2,ByVal lX3,ByVal lY3)
Dim bXY1, bXY2, bXY3, objCopyImage, lCopyHeight, lCopyWidth, lTemp
bXY1 = (lX1 >= 0 And lX1 < m_lWidth) And (lY1 >=0 And lY1 < m_lHeight)
bXY2 = (lX2 >= 0 And lX2 < m_lWidth) And (lY2 >=0 And lY2 < m_lHeight)
bXY3 = (lX3 >= 0 And lX3 < m_lWidth) And (lY3 >=0 And lY3 < m_lHeight)
if bXY1 And bXY2 And bXY3 Then
' Copy the image first
Set objCopyImage = Server.CreateObject("ADODB.Stream")
objCopyImage.Type = 2
objCopyImage.Charset = "x-ansi"
objCopyImage.Open
m_objImage.Position = 0
m_objImage.CopyTo objCopyImage
' Now copy stuff across
lCopyWidth = lX2 - lX1
lCopyHeight = lY2 - lY1
if (lX3 + lCopyWidth) > m_lWidth then lCopyWidth = m_lWidth - lX3
if (lY3 + lCopyHeight) > m_lHeight then lCopyHeight = m_lHeight - lY3
For lTemp = lY1 To (lY1 + lCopyHeight) - 1
objCopyImage.Position = (lTemp * m_lWidth) + lX1
m_objImage.Position = ((lX3 + (lTemp - lY1)) * m_lWidth) + lX3
objCopyImage.CopyTo m_objImage,lCopyWidth
Next
end if
End Sub
' Bounds checked flood fill
Public Sub Flood(ByVal lX,ByVal lY)
' Grab the pixel value at lX,lY, we look for all pixels this colour
Dim xStack, yStack, lPointer, lOldColour, lNewValue, lSouth, lWest, lNorth, lMax
lMax = m_lWidth * m_lHeight
Redim xStack(lMax) ' Maximum number of values possible ever
Redim yStack(lMax)
lPointer = 1
m_objImage.Position = (lY * m_lHeight) + lX
xStack(lPointer) = lX
yStack(lPointer) = lY
' Work out some stuff to try and make this quicker
lOldColour = m_objImage.ReadText(1)
lNewValue = Chr(ForegroundColourIndex)
on error resume next
while lPointer > 0
' Read the top of the stack
lX = xStack(lPointer)
lY = yStack(lPointer)
m_objImage.Position = (lY * m_lHeight) + lX
m_objImage.WriteText lNewValue
m_objImage.Position = (lY * m_lHeight) + lX + 1
if m_objImage.ReadText(1) = lOldColour and (lX + 1) < m_lWidth then
lPointer = lPointer + 1
xStack(lPointer) = lX + 1
yStack(lPointer) = lY
else
m_objImage.Position = ((lY + 1) * m_lHeight) + lX
if m_objImage.ReadText(1) = lOldColour and (lY + 1) < m_lHeight then
lPointer = lPointer + 1
xStack(lPointer) = lX
yStack(lPointer) = lY + 1
else
m_objImage.Position = (lY * m_lHeight) + lX - 1
if m_objImage.ReadText(1) = lOldColour and (lY - 1) >= 0 then
lPointer = lPointer + 1
xStack(lPointer) = lX - 1
yStack(lPointer) = lY
else
m_objImage.Position = ((lY - 1) * m_lHeight) + lX
if m_objImage.ReadText(1) = lOldColour and (lX - 1) >= 0 then
lPointer = lPointer + 1
xStack(lPointer) = lX
yStack(lPointer) = lY - 1
else
lPointer = lPointer - 1
end if
end if
end if
end if
wend
End Sub
' UnboundFlood
' A little better, basically a flood fill with no bounds checking. Don't use this unless
' you are absolutely sure that the shape you're filling in is complete with no holes!
Public Sub UnboundFlood(ByVal lX,ByVal lY)
' Grab the pixel value at lX,lY, we look for all pixels this colour
Dim aStack, lPointer, lOldColour, lNewValue, lSouth, lWest, lNorth, lMax
lMax = m_lWidth * m_lHeight
Redim aStack(lMax) ' Maximum number of values possible ever
lPointer = 1 ' First cab off the rank
m_objImage.Position = (lY * m_lHeight) + lX
aStack(lPointer) = m_objImage.Position
' Work out some stuff to try and make this quicker
lOldColour = m_objImage.ReadText(1)
lNewValue = Chr(ForegroundColourIndex)
lSouth = m_lWidth - 2
lWest = m_lWidth + 2
lNorth = m_lWidth
on error resume next
while lPointer > 0
' Read the top of the stack
m_objImage.Position = aStack(lPointer)
m_objImage.WriteText lNewValue
if m_objImage.ReadText(1) = lOldColour then
lPointer = lPointer + 1
aStack(lPointer) = m_objImage.Position - 1
else
m_objImage.Position = m_objImage.Position + lSouth
if m_objImage.ReadText(1) = lOldColour then
lPointer = lPointer + 1
aStack(lPointer) = m_objImage.Position - 1
else
m_objImage.Position = m_objImage.Position - lWest
if m_objImage.ReadText(1) = lOldColour then
lPointer = lPointer + 1
aStack(lPointer) = m_objImage.Position - 1
else
m_objImage.Position = m_objImage.Position - lNorth
if m_objImage.ReadText(1) = lOldColour then
lPointer = lPointer + 1
aStack(lPointer) = m_objImage.Position - 1
else
lPointer = lPointer - 1
end if
end if
end if
end if
wend
End Sub
' Draw a regular polygon
Public Sub RegularPolygon(lX,lY,lSides,lRadius,lAngle)
Dim Alpha, lTemp, lX2, lY2
Dim aX(), aY()
ReDim aX(lSides - 1),aY(lSides - 1)
Alpha = (2 * PI) / lSides
For lTemp = 1 to lSides ' lSides
aX(lTemp - 1) = CInt(lX + lRadius * Sin(Alpha * lTemp + lAngle))
aY(lTemp - 1) = CInt(lY + lRadius * Cos(Alpha * lTemp + lAngle))
Next
Polygon aX,aY,True
End Sub
' Draw a regular polygon star, skipping just a single point each time
Public Sub RegularStar(lX,lY,lSides,lRadius,lAngle)
Dim Alpha, lTemp, lX2, lY2, lIndex
Dim aX(), aY()
Alpha = (2 * PI) / lSides
if lSides Mod 2 = 0 then
ReDim aX(lSides / 2 - 1),aY(lSides / 2 - 1)
lIndex = 0
For lTemp = 1 to lSides step 2
aX(lIndex) = CInt(lX + lRadius * Sin(Alpha * lTemp + lAngle))
aY(lIndex) = CInt(lY + lRadius * Cos(Alpha * lTemp + lAngle))
lIndex = lIndex + 1
Next
Polygon aX,aY,True
lIndex = 0
For lTemp = 2 to lSides step 2
aX(lIndex) = CInt(lX + lRadius * Sin(Alpha * lTemp + lAngle))
aY(lIndex) = CInt(lY + lRadius * Cos(Alpha * lTemp + lAngle))
lIndex = lIndex + 1
next
Polygon aX,aY,True
else
ReDim aX(lSides - 1),aY(lSides - 1)
For lTemp = 1 to lSides ' lSides
aX(lTemp - 1) = CInt(lX + lRadius * Sin(Alpha * lTemp * 2 + lAngle))
aY(lTemp - 1) = CInt(lY + lRadius * Cos(Alpha * lTemp * 2 + lAngle))
Next
Polygon aX,aY,True
end if
End Sub
' Copied from 1.0.6
Public Sub Polygon(aX,aY,bJoin)
Dim iTemp
if UBound(aX) <> UBound(aY) then exit sub
if UBound(aX) < 1 then exit sub ' Must be more than one point
' Draw a series of lines from arrays aX and aY
for iTemp = 1 to UBound(aX)
Line aX(iTemp - 1),aY(iTemp - 1),aX(iTemp),aY(iTemp)
next
if bJoin then
Line aX(UBound(aX)),aY(UBound(aY)),aX(0),aY(0)
end if
End Sub
' Easy as, err, rectangle?
' Copied from 1.0.6
Public Sub PieSlice(lX,lY,lRadius,sinStartAngle,sinArcAngle,bFilled)
Dim sinActualAngle, sinMidAngle, lX2, lY2, iTemp
Arc lX,lY,lRadius,lRadius,sinStartAngle - 1,sinArcAngle + 1
AngleLine lX,lY,lRadius,sinStartAngle
sinActualAngle = sinStartAngle + sinArcAngle
if sinActualAngle > 360 then
sinActualAngle = sinActualAngle - 360
end if
AngleLine lX,lY,lRadius,sinActualAngle
' Now pick a start flood point at the furthest point from the center
' Divide the arc angle by 2
sinMidAngle = sinStartAngle + (sinArcAngle / 2)
if sinMidAngle > 360 then
sinMidAngle = sinMidAngle - 360
end if
if bFilled then
iTemp = lRadius -2
lY2 = CInt(lY + (Sin(DegreesToRadians(sinMidAngle)) * iTemp))
lX2 = CInt(lX + (Cos(DegreesToRadians(sinMidAngle)) * iTemp))
UnboundFlood lX2,lY2
AngleLine lX,lY,lRadius,sinMidAngle
end if
End Sub
' Copied from 1.0.6
Public Sub Bezier(lX1,lY1,lCX1,lCY1,lCX2,lCY2,lX2,lY2,lPointCount)
Dim sinT, lX, lY, lLastX, lLastY, sinResolution
if lPointCount = 0 then exit sub
sinResolution = 1 / lPointCount
sinT = 0
lLastX = lX1
lLastY = lY1
while sinT <= 1
lX = int(((sinT^3) * -1 + (sinT^2) * 3 + sinT * -3 + 1) * lX1 + ((sinT^3) * 3 + (sinT^2) *-6 + sinT * 3) * lCX1 + ((sinT^3) * -3 + (sinT^2) * 3) * lCX2 + (sinT^3) * lX2)
lY = int(((sinT^3) * -1 + (sinT^2) * 3 + sinT * -3 + 1) * lY1 + ((sinT^3) * 3 + (sinT^2) *-6 + sinT * 3) * lCY1 + ((sinT^3) * -3 + (sinT^2) * 3) * lCY2 + (sinT^3) * lY2)
Line lLastX,lLastY,lX,lY
lLastX = lX
lLastY = lY
sinT = sinT + sinResolution
wend
Line lLastX,lLastY,lX2,lY2
End Sub
' ArcPixel Kindly donated by Richard Deeming (www.trinet.co.uk)
' Copied from 1.0.6
Private Sub ArcPixel(lX, lY, ltX, ltY, sinStart, sinEnd)
Dim dAngle
If ltX = 0 Then
dAngle = Sgn(ltY) * PI / 2
ElseIf ltX < 0 And ltY < 0 Then
dAngle = PI + Atn(ltY / ltX)
ElseIf ltX < 0 Then
dAngle = PI - Atn(-ltY / ltX)
ElseIf ltY < 0 Then
dAngle = 2 * PI - Atn(-ltY / ltX)
Else
dAngle = Atn(ltY / ltX)
End If
If dAngle < 0 Then dAngle = 2 * PI + dAngle
' Compensation for radii spanning over 0 degree marker
if sinEnd > DegreesToRadians(360) and dAngle < (sinEnd - DegreesToRadians(360)) then
dAngle = dAngle + DegreesToRadians(360)
end if
If sinStart < sinEnd And (dAngle > sinStart And dAngle < sinEnd) Then
'This is the "corrected" angle
'To change back, change the minus to a plus
Pixel(lX + ltX, lY + ltY) = ForegroundColourIndex
End If
End Sub
' Arc Kindly donated by Richard Deeming (www.trinet.co.uk), vast improvement on the
' previously kludgy Arc function.
' Copied from 1.0.6
Public Sub Arc(ByVal lX, ByVal lY, ByVal lRadiusX, ByVal lRadiusY, ByVal sinStartAngle, ByVal sinArcAngle)
' Draw an arc at point lX,lY with radius lRadius
' running from sinStartAngle degrees for sinArcAngle degrees
Dim lAlpha, lBeta, S, T, lTempX, lTempY, dStart, dEnd
dStart = DegreesToRadians(sinStartAngle)
dEnd = dStart + DegreesToRadians(sinArcAngle)
lAlpha = lRadiusX * lRadiusX
lBeta = lRadiusY * lRadiusY
lTempX = 0
lTempY = lRadiusY
S = lAlpha * (1 - 2 * lRadiusY) + 2 * lBeta
T = lBeta - 2 * lAlpha * (2 * lRadiusY - 1)
ArcPixel lX, lY, lTempX, lTempY, dStart, dEnd
ArcPixel lX, lY, -lTempX, lTempY, dStart, dEnd
ArcPixel lX, lY, lTempX, -lTempY, dStart, dEnd
ArcPixel lX, lY, -lTempX, -lTempY, dStart, dEnd
Do
If S < 0 Then
S = S + 2 * lBeta * (2 * lTempX + 3)
T = T + 4 * lBeta * (lTempX + 1)
lTempX = lTempX + 1
ElseIf T < 0 Then
S = S + 2 * lBeta * (2 * lTempX + 3) - 4 * lAlpha * (lTempY - 1)
T = T + 4 * lBeta * (lTempX + 1) - 2 * lAlpha * (2 * lTempY - 3)
lTempX = lTempX + 1
lTempY = lTempY - 1
Else
S = S - 4 * lAlpha * (lTempY - 1)
T = T - 2 * lAlpha * (2 * lTempY - 3)
lTempY = lTempY - 1
End If
ArcPixel lX, lY, lTempX, lTempY, dStart, dEnd
ArcPixel lX, lY, -lTempX, lTempY, dStart, dEnd
ArcPixel lX, lY, lTempX, -lTempY, dStart, dEnd
ArcPixel lX, lY, -lTempX, -lTempY, dStart, dEnd
Loop While lTempY > 0
End Sub
' Copied from 1.0.6
Public Sub AngleLine(ByVal lX,ByVal lY,ByVal lRadius,ByVal sinAngle)
' Draw a line at an angle
' Angles start from the top vertical and work clockwise
' Work out the destination defined by length and angle
Dim lX2, lY2
lY2 = (Sin(DegreesToRadians(sinAngle)) * lRadius)
lX2 = (Cos(DegreesToRadians(sinAngle)) * lRadius)
Line lX,lY,lX + lX2,lY + lY2
End Sub
' Bresenham line algorithm, this is pretty quick, only uses point to point to avoid the
' mid-point problem. Copied from 1.0.6
Public Sub Line(ByVal lX1,ByVal lY1,ByVal lX2,ByVal lY2)
Dim lDX, lDY, lXIncrement, lYIncrement, lDPr, lDPru, lP
lDX = Abs(lX2 - lX1)
lDY = Abs(lY2 - lY1)
if lX1 > lX2 then
lXIncrement = -1
else
lXIncrement = 1
end if
if lY1 > lY2 then
lYIncrement = -1
else
lYIncrement = 1
end if
if lDX >= lDY then
lDPr = ShiftLeft(lDY,1)
lDPru = lDPr - ShiftLeft(lDX,1)
lP = lDPr - lDX
while lDX >= 0
Pixel(lX1,lY1) = ForegroundColourIndex
if lP > 0 then
lX1 = lX1 + lXIncrement
lY1 = lY1 + lYIncrement
lP = lP + lDPru
else
lX1 = lX1 + lXIncrement
lP = lP + lDPr
end if
lDX = lDX - 1
wend
else
lDPr = ShiftLeft(lDX,1)
lDPru = lDPr - ShiftLeft(lDY,1)
lP = lDPR - lDY
while lDY >= 0
Pixel(lX1,lY1) = ForegroundColourIndex
if lP > 0 then
lX1 = lX1 + lXIncrement
lY1 = lY1 + lYIncrement
lP = lP + lDPru
else
lY1 = lY1 + lYIncrement
lP = lP + lDPr
end if
lDY = lDY - 1
wend
end if
End Sub
' Draw a custom pattern line fed by sPattern
Public Sub CustomLine(ByVal lX1,ByVal lY1,ByVal lX2,ByVal lY2,sPattern)
Dim lDX, lDY, lXIncrement, lYIncrement, lDPr, lDPru, lP, lPatternIndex
if sPattern = "" then sPattern = "1"
lDX = Abs(lX2 - lX1)
lDY = Abs(lY2 - lY1)
if lX1 > lX2 then
lXIncrement = -1
else
lXIncrement = 1
end if
if lY1 > lY2 then
lYIncrement = -1
else
lYIncrement = 1
end if
lPatternIndex = 1
if lDX >= lDY then
lDPr = ShiftLeft(lDY,1)
lDPru = lDPr - ShiftLeft(lDX,1)
lP = lDPr - lDX
while lDX >= 0
Pixel(lX1,lY1) = CLng(Mid(sPattern,lPatternIndex,1))
lPatternIndex = lPatternIndex + 1
if lPatternIndex > Len(sPattern) then lPatternIndex = 1
if lP > 0 then
lX1 = lX1 + lXIncrement
lY1 = lY1 + lYIncrement
lP = lP + lDPru
else
lX1 = lX1 + lXIncrement
lP = lP + lDPr
end if
lDX = lDX - 1
wend
else
lDPr = ShiftLeft(lDX,1)
lDPru = lDPr - ShiftLeft(lDY,1)
lP = lDPR - lDY
while lDY >= 0
Pixel(lX1,lY1) = CLng(Mid(sPattern,lPatternIndex,1))
lPatternIndex = lPatternIndex + 1
if lPatternIndex > Len(sPattern) then lPatternIndex = 1
if lP > 0 then
lX1 = lX1 + lXIncrement
lY1 = lY1 + lYIncrement
lP = lP + lDPru
else
lY1 = lY1 + lYIncrement
lP = lP + lDPr
end if
lDY = lDY - 1
wend
end if
End Sub
' Copied from 1.0.6
Public Sub Rectangle(ByVal lX1,ByVal lY1,ByVal lX2,ByVal lY2)
' Easy as pie, well, actually pie is another function... draw four lines
Line lX1,lY1,lX2,lY1
Line lX2,lY1,lX2,lY2
Line lX2,lY2,lX1,lY2
Line lX1,lY2,lX1,lY1
End Sub
Public Sub FilledRectangle(ByVal lX1,ByVal lY1,ByVal lX2,ByVal lY2)
' Make a filled rectangle really quickly
Dim lWidth, lHeight, lTemp
lWidth = lX2 - lX1
lHeight = lY2 - lY1
if lX2 > m_lWidth then lWidth = m_lWidth - lX1
if lY2 > m_lHeight then lHeight = m_lHeight - lY1
For lTemp = lY1 to (lY1 + lHeight)
m_objImage.Position = (lTemp * m_lWidth) + lX1
m_objImage.WriteText String(lWidth,Chr(ForegroundColourIndex))
Next
End Sub
' Copied from 1.0.6
Public Sub Circle(ByVal lX,ByVal lY,ByVal lRadius)
Ellipse lX,lY,lRadius,lRadius
End Sub
' Bresenham ellispe, pretty quick also, uses reflection, so rotation is out of the
' question unless we perform a matrix rotation after rendering the ellipse coords
' copied from 1.0.6
Public Sub Ellipse(ByVal lX,ByVal lY,ByVal lRadiusX,ByVal lRadiusY)
' Draw a circle at point lX,lY with radius lRadius
Dim lAlpha,lBeta,S,T,lTempX,lTempY
lAlpha = lRadiusX * lRadiusX
lBeta = lRadiusY * lRadiusY
lTempX = 0
lTempY = lRadiusY
S = lAlpha * (1 - 2 * lRadiusY) + 2 * lBeta
T = lBeta - 2 * lAlpha * (2 * lRadiusY - 1)
Pixel(lX + lTempX,lY + lTempY) = ForegroundColourIndex
Pixel(lX - lTempX,lY + lTempY) = ForegroundColourIndex
Pixel(lX + lTempX,lY - lTempY) = ForegroundColourIndex
Pixel(lX - lTempX,lY - lTempY) = ForegroundColourIndex
Do
if S < 0 then
S = S + 2 * lBeta * (2 * lTempX + 3)
T = T + 4 * lBeta * (lTempX + 1)
lTempX = lTempX + 1
elseif T < 0 then
S = S + 2 * lBeta * (2 * lTempX + 3) - 4 * lAlpha * (lTempY - 1)
T = T + 4 * lBeta * (lTempX + 1) - 2 * lAlpha * (2 * lTempY - 3)
lTempX = lTempX + 1
lTempY = lTempY - 1
else
S = S - 4 * lAlpha * (lTempY - 1)
T = T - 2 * lAlpha * (2 * lTempY - 3)
lTempY = lTempY - 1
end if
Pixel(lX + lTempX,lY + lTempY) = ForegroundColourIndex
Pixel(lX - lTempX,lY + lTempY) = ForegroundColourIndex
Pixel(lX + lTempX,lY - lTempY) = ForegroundColourIndex
Pixel(lX - lTempX,lY - lTempY) = ForegroundColourIndex
loop while lTempY > 0
End Sub
' Vector font support
' These fonts are described in terms of points on a grid with simple
' X and Y offsets. These functions take elements of a string and render
' them from arrays storing character vector information. Vector fonts are
' have proportional widths, unlike bitmapped fonts which are fixed in size
' The format for the vector array is simply a variable length list of x y pairs
' the sub DrawVectorChar renders the single character from the array.
' The other advantage of vector fonts is that they can be scaled :)
' Maybe add an angle value?
Public Sub DrawVectorTextWE(ByVal lX,ByVal lY,sText,lSize)
Dim iTemp, lCurrentStringX
lCurrentStringX = lX
For iTemp = 1 to Len(sText)
lCurrentStringX = lCurrentStringX + DrawVectorChar(lCurrentStringX,lY,Mid(sText,iTemp,1),lSize,true) + int(lSize)
Next
End Sub
Public Sub DrawVectorTextNS(ByVal lX,ByVal lY,sText,lSize)
Dim iTemp, lCurrentStringY
lCurrentStringY = lY
For iTemp = 1 to Len(sText)
lCurrentStringY = lCurrentStringY + DrawVectorChar(lX,lCurrentStringY,Mid(sText,iTemp,1),lSize,false) + int(lSize)
Next
End Sub
Private Function DrawVectorChar(ByVal lX,ByVal lY,sChar,lSize,bOrientation)
Dim iTemp, aFont, lLargest
if IsArray(VLetter) then
if sChar <> " " then
aFont = VFont(sChar)
if bOrientation then
lLargest = aFont(1,0) * lSize
else
lLargest = aFont(1,1) * lSize
end if
for iTemp = 1 to UBound(aFont,1) - 1
if bOrientation then
if aFont(iTemp,2) = 1 then ' Pen down
Line lX + aFont(iTemp - 1,0) * lSize,lY + aFont(iTemp - 1,1) * lSize,lX + aFont(iTemp,0) * lSize,lY + aFont(iTemp,1) * lSize
end if
if (aFont(iTemp,0) * lSize) > lLargest then
lLargest = aFont(iTemp,0) * lSize
end if
else
if aFont(iTemp,2) = 1 then ' Pen down
Line lX + aFont(iTemp - 1,0) * lSize,lY + aFont(iTemp - 1,1) * lSize,lX + aFont(iTemp,0) * lSize,lY + aFont(iTemp,1) * lSize
end if
if (aFont(iTemp,1) * lSize) > lLargest then
lLargest = aFont(iTemp,1) * lSize
end if
end if
next
else
lLargest = lSize * 3
end if
else
Alert "font.asp has not been included into this canvas project, this is needed for displaying fonts",false
end if
' Return the width of the character
DrawVectorChar = lLargest
End Function
' Return the pixel size of the text going WE and NS
Public Function GetTextWEWidth(sText)
Dim lWidth, lTemp
' Tricky, get the width of all the characters
lWidth = 0
For lTemp = 1 to Len(sText)
lWidth = lWidth + Len(Font(Mid(sText,lTemp,1))(0))
Next
GetTextWEWidth = lWidth
End Function
' All characters have the same height in the fonts
Public Function GetTextWEHeight(sText)
GetTextWEHeight = UBound(Letter) + 1
End Function
' Find the widest character
Public Function GetTextNSWidth(sText)
Dim lWidth, lTemp
lWidth = 0
For lTemp = 1 to Len(sText)
if Len(Font(Mid(sText,lTemp,1))(0)) > lWidth then
lWidth = Len(Font(Mid(sText,lTemp,1))(0))
end if
Next
GetTextNSWidth = lWidth
End Function
Public Function GetTextNSHeight(sText)
' Easy one, multiply the number of character by the Letter array size
GetTextNSHeight = Len(sText) * (UBound(Letter) + 1)
End Function
' Bitmap font support
Public Sub DrawTextWE(ByVal lX,ByVal lY,sText)
' Render text at lX,lY
' There's a global dictionary object called Font and it should contain all the
' letters in arrays of a 5x5 grid
Dim iTemp1, iTemp2, iTemp3, bChar, lCurrentX
if IsArray(Letter) then
For iTemp1 = 0 to UBound(Letter) - 1
lCurrentX = lX
For iTemp2 = 1 to len(sText)
For iTemp3 = 1 to Len(Font(Mid(sText,iTemp2,1))(iTemp1))
bChar = Mid(Font(Mid(sText,iTemp2,1))(iTemp1),iTemp3,1)
if bChar <> "0" then Pixel(lCurrentX,lY + iTemp1) = CLng(bChar)
lCurrentX = lCurrentX + 1
next
next
next
else
Alert "font.asp has not been included into this canvas project, this is needed for displaying fonts",false
end if
End Sub
Public Sub DrawTextNS(ByVal lX,ByVal lY,sText)
' Render text at lX,lY
' There's a global dictionary object called Font and it should contain all the
' letters in arrays of a 5x5 grid
Dim iTemp1, iTemp2, iTemp3, bChar
if IsArray(Letter) then
for iTemp1 = 1 to len(sText)
for iTemp2 = 0 to UBound(Letter) - 1
for iTemp3 = 1 to len(Font(Mid(sText,iTemp1,1))(iTemp2))
bChar = Mid(Font(Mid(sText,iTemp1,1))(iTemp2),iTemp3,1)
if bChar <> "0" then
Pixel(lX + iTemp3,lY + ((iTemp1 - 1) * (UBound(Letter) + 1)) + iTemp2) = CLng(bChar)
end if
next
next
next
else
Alert "font.asp has not been included into this canvas project, this is needed for displaying fonts",false
end if
End Sub
Public Sub Clear()
' Clear the image
m_objImage.Close
m_objImage.Open
m_objImage.WriteText String(m_lWidth * m_lHeight,Chr(BackgroundColourIndex))
End Sub
public sub Resize(ByVal lNewWidth,ByVal lNewHeight,bPreserve)
Dim objNewImage, lCopyWidth, lCopyHeight, lTemp
if bPreserve then
' Make the new canvas
Set objNewImage = Server.CreateObject("ADODB.Stream")
objNewImage.Type = 2
objNewImage.Charset = "x-ansi"
objNewImage.Open
objNewImage.WriteText String(lNewWidth * lNewHeight,Chr(BackgroundColourIndex))
lCopyWidth = m_lWidth
lCopyHeight = m_lHeight
if m_lWidth >= lNewWidth then lCopyWidth = lNewWidth
if m_lHeight >= lNewHeight then lCopyHeight = lNewHeight
For lTemp = 0 To lCopyHeight
m_objImage.Position = (lTemp * m_lWidth)
objNewImage.Position = (lTemp * lNewWidth)
m_objImage.CopyTo objNewImage,lCopyWidth
Next
m_objImage.Close
m_objImage.Open
objNewImage.Position = 0
objNewImage.CopyTo m_objImage
m_lWidth = lNewWidth
m_lHeight = lNewHeight
else
m_lWidth = lNewWidth
m_lHeight = lNewHeight
Clear
end if
end sub
Private Sub Alert(sText,bAllowImage)
' Dump errors out
if ErrorsToImage and bAllowImage then
GlobalColourTable(0) = RGB(255,255,255)
GlobalColourTable(1) = RGB(255,128,0)
Resize 800,30,False
ForegroundColourIndex = 1
DrawTextWE 0,0,"ERROR: " & sText
DrawTextWE 1,0,"ERROR: " & sText
Write
end if
if ErrorsToResponse and not errorstoimage then Response.Write sText & "<br>"
if ErrorsToIISLog then Response.AppendToLog sText
if ErrorsHalt then Response.End
End Sub
' 0-0-0-0-0-0-0-0-0-0-0-0-0-0- Image management functions -0-0-0-0-0-0-0-0-0-0-0-0-0-0
' Dump the image
Public Sub Write()
Response.ContentType = "image/gif"
Response.AddHeader "Content-Disposition","filename=image.gif"
Response.BinaryWrite ImageData().Read
End Sub
Public Sub SaveGIF(sFilename)
ImageData.SaveToFile sFilename,1 ' adSaveCreateNotExist
End Sub
' Raw image data
Public Function ImageData()
Dim objTemp, lTemp, sText, objTempStream, lSize
Set objTemp = Server.CreateObject("ADODB.Stream")
' Do this all in x-ansi and then convert to binary
objTemp.Type = 2
objTemp.Charset = "x-ansi" ' x-ansi is the solution!
objTemp.Open
objTemp.WriteText "GIF89a"
objTemp.WriteText MakeWord(m_lWidth)
objTemp.WriteText MakeWord(m_lHeight)
objTemp.WriteText MakeByte(&HF7)
objTemp.WriteText MakeByte(BackgroundColourIndex)
objTemp.WriteText MakeByte(&H00)
For lTemp = 0 To UBound(GlobalColourTable) - 1
objTemp.WriteText MakeByte(Red(GlobalColourTable(lTemp)))
objTemp.WriteText MakeByte(Green(GlobalColourTable(lTemp)))
objTemp.WriteText MakeByte(Blue(GlobalColourTable(lTemp)))
Next
if UseTransparency then
objTemp.WriteText MakeWord(&HF921)
objTemp.WriteText MakeWord(&H0104)
objTemp.WriteText MakeWord(&H0000)
objTemp.WriteText MakeByte(TransparentColourIndex)
objTemp.WriteText MakeByte(&H00)
end if
if Comment <> "" then
objTemp.WriteText MakeWord(&HFE21)
sText = Left(Comment,&HFF) ' Truncate to 255 characters
objTemp.WriteText MakeByte(Len(sText))
objTemp.WriteText sText
objTemp.WriteText MakeByte(&H00)
end if
objTemp.WriteText ","
objTemp.WriteText MakeWord(&H00)
objTemp.WriteText MakeWord(&H00)
objTemp.WriteText MakeWord(m_lWidth)
objTemp.WriteText MakeWord(m_lHeight)
objTemp.WriteText MakeWord(&H0700)
Set objTempStream = Server.CreateObject("ADODB.Stream")
objTempStream.Charset = "x-ansi"
objTempStream.Type = 2
objTempStream.Open
m_objImage.Position = 0
' Insert clearcodes
while not m_objImage.EOS
objTempStream.WriteText m_objImage.ReadText(&H7E)
objTempStream.WriteText Chr(&H80)
wend
objTempStream.Position = 0
while not objTempStream.EOS
lSize = objTempStream.Size - objTempStream.Position
if lSize > &HFF then lSize = &HFF
objTemp.WriteText MakeByte(lSize)
objTempStream.CopyTo objTemp,lSize
wend
objTemp.WriteText MakeWord(&H8100)
objTemp.WriteText MakeWord(&H3B00)
objTemp.Position = 0
objTemp.Type = 1
Set ImageData = objTemp
End Function
Public Sub LoadBMP(sFilename)
Dim objStream, lOffset, lNewWidth, lNewHeight, lBPP, lCompression, lImageSize, lTemp
Dim lRed,lGreen,lBlue,lPad, lLineSize
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Charset = "x-ansi"
objStream.Type = 2
objStream.Open
on error resume next
objStream.LoadFromFile sFilename
if err.number <> 0 then
alert "Failure calling LoadBMP: " & err.description & "-" & sFilename,true
end if
on error goto 0
LoadBMPFromStream objStream
objStream.Close
Set objStream = Nothing
End Sub
Public Sub LoadBMPFromStream(objStream)
Dim lOffset, lNewWidth, lNewHeight, lBPP, lCompression, lImageSize, lTemp
Dim lRed,lGreen,lBlue,lPad, lLineSize
' Decode the bitmap here
if objStream.ReadText(2) = "BM" then
objStream.Position = 10
lOffset = GetLong(objStream.ReadText(4))
objStream.Position = 18
lNewWidth = GetLong(objStream.ReadText(4))
lNewHeight = GetLong(objStream.ReadText(4))
objStream.Position = 28
lBPP = GetWord(objStream.ReadText(2))
lCompression = GetLong(objStream.ReadText(4))
lImageSize = GetLong(objStream.ReadText(4))