我该如何解释这个VB6代码?

时间:2013-08-29 18:37:01

标签: vb6 postscript

我继承了一个打印出货标签的VB程序。我们需要更新打印的条形码,并且我试图了解现有程序正在做什么。有一堆“WrittenData”(存储为“s”)似乎包含用于生成标签的Postscript代码,但我没有找到任何指定这半东西含义的地方。

Public Function PostScriptItem(address As Variant, Optional intPageNumberOut As Integer = 1, Optional intPageNumberIn As Integer = 2) As String

  ' 0 - MatchUpId
  ' 1 - Our Barcode
  ' 2 - Outgoing PostNet Code
  ' 3 - Outgoing Line 1
  ' 4 - Outgoing Line 2 (optionally EMPTY)
  ' 5 - Outgoing Line 3
  ' 6 - Outgoing Line 4
  ' 7 - Outgoing PlaNET Code
  ' 8 - Incoming PostNet Code
  ' 9 - Incoming Line 1
  '10 - Incoming Line 2 (optionally EMPTY)
  '11 - Incoming Line 3
  '12 - Incoming Line 4
  '13 - Incoming PlaNET Code
  '14 - Title Id

  'Escape Parenthesis and Backslashes
  Dim tPos As Integer
  For tPos = 0 To 14 Step 1
    address(tPos) = Replace(address(tPos), "\", "\\")
    address(tPos) = Replace(address(tPos), "(", "\(")
    address(tPos) = Replace(address(tPos), ")", "\)")
  Next tPos

  Dim s As String
  Dim pos As Integer
  Dim fsize As Integer

  Dim strBarcodeCaption As String

  strBarcodeCaption = address(1) & "    " & address(14) & "    " & address(0)

  pos = 50
  fsize = 12

  s = s & "%%Page: " & CStr(intPageNumberOut) & " " & CStr(intPageNumberOut) & vbCrLf & _
          "<< /Duplex true >> setpagedevice" & vbCrLf & _
          "<< /Tumble true >> setpagedevice" & vbCrLf & _
          "%%BeginPageSetup" & vbCrLf & _
          "180 rotate" & vbCrLf & _
          "/pagelevel save def" & vbCrLf & _
          "%%EndPageSetup" & vbCrLf & _
          "newpath" & vbCrLf & _
          "-338 -205 translate" & vbCrLf & _
          "/Courier-Bold findfont 6 scalefont setfont" & vbCrLf & _
          "newpath" & vbCrLf

  s = s & "32 104 moveto (" & strBarcodeCaption & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  s = s & "12 -450 translate" & vbCrLf & _
          "62 104 moveto (" & strBarcodeCaption & ") show" & vbCrLf & _
          "newpath" & vbCrLf & _
          "30 80 moveto (^104" & address(1) & ") (height=0.3) code128 barcode" & vbCrLf & _
          "newpath" & vbCrLf

  s = s & "/Helvetica findfont 11 scalefont setfont" & vbCrLf & _
          "0 " & CStr(pos) & " moveto (" & address(3) & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  pos = pos - fsize

  If address(4) <> Empty Then
    s = s & "0 " & CStr(pos) & " moveto (" & address(4) & ") show" & vbCrLf & _
            "newpath" & vbCrLf

    pos = pos - fsize
  End If

  s = s & "0 " & CStr(pos) & " moveto (" & address(5) & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  pos = pos - fsize

  s = s & "0 " & CStr(pos) & " moveto (" & address(6) & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  pos = pos - fsize - 5

  s = s & "1 " & CStr(pos) & " moveto (" & address(2) & ") () postnet barcode" & vbCrLf & _
          "%%PageTrailer" & vbCrLf & _
          "pagelevel restore" & vbCrLf & _
          "showpage" & vbCrLf

  s = s & "%%Page: " & CStr(intPageNumberIn) & " " & CStr(intPageNumberIn) & vbCrLf & _
          "<< /Duplex true >> setpagedevice" & vbCrLf & _
          "<< /Tumble true >> setpagedevice" & vbCrLf & _
          "%%BeginPageSetup" & vbCrLf & _
          "/pagelevel save def" & vbCrLf & _
          "210 711 translate" & vbCrLf & _
          "%%EndPageSetup" & vbCrLf & _
          "newpath" & vbCrLf & _
          "/Courier-Bold findfont 6 scalefont setfont" & vbCrLf & _
          "0 21 moveto (" & address(1) & "    " & address(0) & ") show" & vbCrLf & _
          "gsave" & vbCrLf & _
          "0.5 0.5 scale" & vbCrLf & _
          "0 12 moveto (^104" & address(1) & ") (height=0.3) code128 barcode" & vbCrLf & _
          "grestore" & vbCrLf & _
          "newpath" & vbCrLf & _
          "32 0 moveto (" & address(14) & ") show" & vbCrLf & _
          "newpath" & vbCrLf & _
          "/Helvetica findfont 11 scalefont setfont" & vbCrLf & _
          "-70 -180 translate" & vbCrLf

  pos = 56

  s = s & "0 " & CStr(pos) & " moveto (" & address(9) & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  pos = pos - fsize

  If address(10) <> Empty Then
    s = s & "0 " & CStr(pos) & " moveto (" & address(10) & ") show" & vbCrLf & _
            "newpath" & vbCrLf

    pos = pos - fsize
  End If

  s = s & "0 " & CStr(pos) & " moveto (" & address(11) & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  pos = pos - fsize

  s = s & "0 " & CStr(pos) & " moveto (" & address(12) & ") show" & vbCrLf & _
          "newpath" & vbCrLf

  pos = pos - fsize - 5

  s = s & "1 " & CStr(pos) & " moveto (" & address(8) & ") () postnet barcode" & vbCrLf & _
          "%%PageTrailer" & vbCrLf & _
          "pagelevel restore" & vbCrLf & _
          "showpage" & vbCrLf

  PostScriptItem = s

End Function

我需要更改“address(2)”和“address(8)”的内容,并使用不同的字体来打印它们。我尝试将新字体放在项目字体文件夹中并以“postnet”和“code128”的方式引用它,但这给我留下了一个完全空白的标签。 “code128”字体似乎在一个名为“postscript_main.ps”的单独文件中定义,我不知道如何将新字体合并到其中,我真的迷失了,并希望找到一些线索或链接到某些文档让我朝着正确的方向前进。

0 个答案:

没有答案
相关问题