Skip to main content

Posts

Showing posts from July, 2017

A Programming Pattern to Create a Modeless Dialog with Adobe ScriptUI

I'd like to create a dialog box to input some special characters onto InDesign without running the dialog every time, after I clicked on some button to input characters. A modeless dialog is the choice. But I got many crashes. Finally, with the sample from Adobe, I got a stable programming pattern, which works with Adobe CC. Here is the code: #targetengine session; // the above line is necessary to create a modeless dialog with // var win = new Window("palette", ...); // // refer to the sample program from Adobe: "SnpCreateDialog.jsx". // Which is usually located at the folder (Windows): // C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\SDK\Samples\javascript function AModelessDialog() { this.windowRef = null; } function setupWindow() { var ww = new Window("palette", "A Modeless Dialog"); addComponents(ww); return ww; } AModelessDialog.prototype.run = function() { var win = setupWindow(); this.windowRef = win; w...

Try to Add a Language Support to Prism

I try to add a language support to Prism, and I find a way to do so easly. The design of Prism allows a programmer to develop its functionality with the development environment of browsers. It also supports the development with Node.js. I don't have experience with the browser environment. That why I try to use Node.js first. Using Node.js to develop the plugin and language support allows me work with IDE without lost my familiar debugging steps: break points, watchs, call stacks, ... . I use Visual Studio Code as my IDE. Create a folder, Copy prism.js into the folder, (the prism.js is downloaded for the website of Prism) From the menu: File > Open Folder, Now the prism.js is in the Explorer of Visual Studio Code. Add a new javascript source call app.js, with the code: var loadedModule = require('./prism'); var pyCode = 'print \"Done.\"'; // a python code var result = Prism.tokenize(pyCode, Prism.languages.python); var...

Tool to Convert Source Code to HTML Encoded Text in C#

It will be convenient to have a tool converting the source code to HTML encoded text, before I can post it on my blog article. The following C# code is my tool to do the job: public FormMain() { InitializeComponent(); } private void buttonExit_Click(object sender, EventArgs e) { Close(); } private void buttonRun_Click(object sender, EventArgs e) { string src = textBoxSrc.Text; string html = System.Net.WebUtility.HtmlEncode(src); textBoxHTML.Text = html; textBoxHTML.SelectAll(); textBoxHTML.Copy(); } private void textBoxSrc_MouseClick(object sender, MouseEventArgs e) { textBoxSrc.Text = ""; } The UI: Usage: Click on the textBoxSrc, the text in textBoxSrc will be cleaned. (line 26) Copy the source code to the textBoxSrc. Click the buttonRun. The converted text will be displayed on the textBoxHTML, in the same time, the text will also be copied to the clipboard for further use. (line 13 ~ 21) You may use Visual Studio Community to create the p...

Visual Studio + Node.js: Javascript Development

In the beginning, I just planned to install a code-highlighter plugin for my Blog. After the testing on Syntaxhighlighter and Prism, I decided to add a language support of PostScript. The string data of PostScript has "(" and ")" as the deliminator: string begin and string end. According the red book: "A literal text string consists of an arbitrary number of characters enclosed in ( and ). Any characters may appear in the string other than (, ), and \, which must be treated specially. Balanced pairs of parentheses in the string require no special treatment." There are some more lines to describe about \, the "escape". I just leave them in the book. So, the issue is, I need to figure out, how to use regex to retrieve the PostScript strings from the source code to give them a color. I need to run and debug my code together with Prism (maybe Syntaxhighlighter) and to see if I can find some solution. So, I dig into finding a Javascrip...

Another Highlighter: Prism

Prism  is another highlighter, which is designed to meet the modern standard. To extend the functionality of Prism and to add a new language support for Prism are not difficult. Here are examples of three different highlighters: Prism #targetengine "session" main(); function main() { StyleSetup(); myWorking(); myCleanup(); } function StyleSetup() { var myDocument; if (app.documents.length == 0) { myDocument = app.documents.add(); } else { myDocument = app.documents.item(0); } myCompsiteFontsSetup(myDocument); } function myWorking() { } function myCleanup() { } // ===== Composite Fonts ================================== function SetupOneCompFont(myDocument, nFName, nHanName, nHanStyle, nRomName, nRomStyle) { var nCF = myDocument.compositeFonts.item(nFName); try { var myName = nCF.name; } catch (myError) { nCF = myDocument.compositeFonts.add(); with (nCF) { name = nFName; var idx; for (idx = 0; idx < 3; idx++) { //console.log(...

Build Syntaxhighlighter on Windows 10

When I built the Syntaxhightlighter 4.0.1 on Windows 10 last week, I got errors. After I read the discuss chain ( link ), I followed the post from MayaLekova to install "Windows Subsystem for Linux". And it really worked. The build results were same as those from my Mac mini. Bash on ubuntu on Windows Please follow Jack Hammons's " Installation guide " of "Bash on ubuntu on Windows". Here I took a short note about what I had done: 1. Make sure the system is a 64-bit Windows 10. 2. From "Start" (開始按鈕) > "Settings" (設定) > "Update and Security" (更新與安全性) We can turn the "Developer Mode" on. (2.1) If there is a step asking you to reboot the computer, please wait until to the last step in this description. After the "Developer Mode" is enabled and some software has been downloaded. 3. From "Start" (開始按鈕), search "Windows Features" (開啟或關閉 Windows 功能) ...

4. Programming:

4.1 C/C++: 4.2 C#: 2017 07: Tool to Convert Source Code to HTML Encoded Text in C# 2015 01: Flicker Free Drawing with Winform in C# 4.3 Javascript: 2017 07: Try to Add a Language Support to Prism 2017 07: Visual Studio + Node.js: Javascript Development 4.4 Python:

2. InDesign:

2017 07: A Programming Pattern to Create a Modeless Dialog with Adobe ScriptUI 2018 03: InDesign Scripting with ScriptUI: How to Move Cursor and Select Text 2018 03: InDesign Scripting with ScriptUI: Add a TestIt Button to Play Around

Posting Source Code in Blogger

There are ways to post source code in Blogger. I had tried Google Code Prettify and SyntaxHighlighter. I found SyntaxHighlighter, which meets my needs of line numbers, long lines and syntax highlights. I downloaded the version 4.0.1 from:  GitHub.SyntaxHighlighter , and tried to build it. But, there were many build-issues on Windows (10). There are some solutions on the web, but I didn't try them. After switching to my Mac mini and installing the node.js 6.11.0 LTS. (Version 8.1.3 won't work. It produced too many warnings.) The build was almost smooth, but with just a warning about not supporting the python version 2.7. What I installed on my Mac mini is 3.6.1. Despite of this warning, I got the files: syntaxhighlighter.js and theme.css with a sample index.html. Together, they worked fine. Here are my tests: SyntaxHightlighter: def foo(): for ii in range(10): print ii if ii > 10: print "Error." print "This is a very very very v...

LaTeX on Blogger

更新: MathJax 在 2017/4/30 關閉了 CDN,並且提出了修改的方法。 (請參考: MathJax CDN shutting down on April 30, 2017. Alternatives available. ) 新的 script 如下: <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"> MathJax.Hub.Config({ extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js"], jax: ["input/TeX", "output/HTML-CSS"], tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], }, "HTML-CSS": { availableFonts: ["TeX"] } }); </script> 原來的文章接續如下: 畢氏定理: $a^2 + b^2 = c^2$ LaTeX 的寫法: $a^2 + b^2 = c^2$ 一元二次方程式的解: $ax^2 + bx + c = 0, a \neq 0$ $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ LaTeX 的寫法: $ax^2 + bx + c = 0, a \neq 0$ $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ 讓 Blogger 可以顯示 $\LaTeX$ 的算式,請參考討論串 ...