writing a word document with diagrams

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Uri Blass
Posts: 10267
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

writing a word document with diagrams

Post by Uri Blass »

I would like to write a word document with diagrams like the following diagram for every square in the board

http://www.jinchess.com/chessboard/?p=- ... 6g8%2Ce4h1

Practically I can copy the diagram to a word document simply by the following actions on the relevant link:

1)Edit->select all
2)Edit->copy

When later I simply paste what I copied to the word document.

I have no idea what I paste to the word document and how the word document understand it.

I would like to write a program that generates some file that I can copy and paste to get 64 diagrams for every square of the board and I have no idea how to do it(I can write a program to generate links but I prefer to write a program that generates directly what I copy).

The reason that I like to write a program to do it is that I want to use it for teaching chess for beginners that have learning problems.

I know that at least when I talk about the knight then there are adults with learning disabilities that really have problems to mark all the squares that the knight can go into them fast and correctly and maybe training in this type of exercise until they can do it at the same speed that I can do it can help them.

If you ask how I got the link then the answer is simple

1)goto
http://www.jinchess.com/chessboard/composer/

2)put a piece on the board

3)click marking and choose add arrow for all the arrows you want.

Uri
abulmo
Posts: 151
Joined: Thu Nov 12, 2009 6:31 pm

Re: writing a word document with diagrams

Post by abulmo »

Uri Blass wrote: I have no idea what I paste to the word document and how the word document understand it.
An image using the PNG (Portable Network Graphics) format.
Uri Blass wrote: I would like to write a program that generates some file that I can copy and paste to get 64 diagrams for every square of the board and I have no idea how to do it(I can write a program to generate links but I prefer to write a program that generates directly what I copy).
Well, just write a program that generate images. There are several image formats, often with a library to manipulate them. To use images in a Word document, I would personnaly look for a vector format like eps or svg rather than a bitmap format like png.
Richard
tvrzsky
Posts: 128
Joined: Sat Sep 23, 2006 7:10 pm
Location: Prague

Re: writing a word document with diagrams

Post by tvrzsky »

Is it so necessary for you to have a Word document? If not, then I suggest you to create it in Postscript and eventually export it to a PDF file, for instance using Ghostscript. I use this method for example when I generate automatic analysis of a game with some strong engine. Here is a such PDF:
http://tvrzsky.ic.cz/files/game.pdf
and this is related Postcript file:
http://tvrzsky.ic.cz/files/game.ps
Have a look at .ps file with some text editor. It is actually programming language, so it is not very hard task to write some program which generates such script. Adding any vector graphic is very easy and straightforward in postcript.
Of course it is possible to create Word documents automatically as well. I used this method before I switched to postscript. You need to create some macro in Word which converts plain text file to a Word file, adds formatting and maybe it would be possible to include some graphics this way as well but I am not sure about it.
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: writing a word document with diagrams

Post by Fguy64 »

Hi Uri

As yu can see there are a few ways to get the job done. I can think of at least three different ways to put a graphic into a Word Document, all pretty much boil down to the same thing.

Another way is if you already have a .jpg file on your hard drive, you can add it to the Word document by clicking on insert from the menu bar, then picture, insert from file.

How are you with tables? they are very useful for arranging the pictures on the page.

Finally, if you are still looking for ideas, pay a visit to http://www.chessvariants.com/ They have a very large section on Desktop publishing, with all kinds of ways to put diagrams into documents.
Uri Blass
Posts: 10267
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: writing a word document with diagrams

Post by Uri Blass »

Thanks for all the replies.

Unfortunately I still do not understand how to put graphic into a word document or into a pdf file

I want to do it because I want to be able to send by email diagrams inside documents to other people.

It is not important if it is pdf file or word file and the only important thing is that people are going to be able to get it without buying some new software.

I would like simply to copy some text file that is going to give me a diagram so I may later write a program that generate text file that if you copy it give you set of diagrams.

I do not understand what is
An image using the PNG (Portable Network Graphics) format.

It is going to be productive if somebody explain me exactly what the computer does when it copy a diagram from some site to word document by copy and paste.

What is exactly the content of the thing that the computer copy and how can I develop a program that generates it.

When I look at .ps file with some text editor it is not clear to me and they clearly have more than one diagram.

It is not clear to me exactly what I need to generate a single diagram
and I want to start by seeing code to generate empty diagram with no pieces or diagrams with a single piece(no diagram with many pieces)

I see a diagram with many pieces when the part of the .ps file is probably the following part that I understand nothing from it.

() show 90 zalom
/wdth 90.000000 def
.84 (!""""""""#) /ChessMerida NastavFont
(!""""""""#) prndl
($t+ WlV T%) prndl
($Oo+m+oOo%) prndl
($ +o+ M +%) prndl
($+ +oO +v%) prndl
($ + +p+ +%) prndl
($+ +p+nPp%) prndl
($pPpN Pb+%) prndl
($R Bq+rK %) prndl
(/\(\(\(\(\(\(\(\(\)) prndl
0 vel_d rmoveto
20 zalom
MainFont setfont
( Rybka: 8. ... bf8-e7 -6) prnl
() prnl
()currentrgbcolor .97 0 0 setrgbcolor currentpoint 125 49 rmoveto currentfont 5 scalefont setfont (33) show moveto setrgbcolor MainFont setfont
() prnl
Piero
Posts: 5
Joined: Wed Mar 08, 2006 8:38 pm

Re: writing a word document with diagrams

Post by Piero »

This seems to be a text chessboard. For example, just copy and paste the text below and set "Chess Merida"as the text font and there will be a diagram. The nice thing about this is that you can make diagrams in any text editor this way.

Code: Select all

t+ WlV T
Oo+m+oOo
 +o+ M +
+ +oO +v
 + +p+ +
+ +p+nPp
pPpN Pb+ 
R Bq+rK 
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: writing a word document with diagrams

Post by Fguy64 »

User avatar
Roman Hartmann
Posts: 295
Joined: Wed Mar 08, 2006 8:29 pm

Re: writing a word document with diagrams

Post by Roman Hartmann »

You might want to consider LaTeX for your task.

Roman
tvrzsky
Posts: 128
Joined: Sat Sep 23, 2006 7:10 pm
Location: Prague

Re: writing a word document with diagrams

Post by tvrzsky »

Piero wrote:This seems to be a text chessboard. For example, just copy and paste the text below and set "Chess Merida"as the text font and there will be a diagram. The nice thing about this is that you can make diagrams in any text editor this way.

Code: Select all

t+ WlV T
Oo+m+oOo
 +o+ M +
+ +oO +v
 + +p+ +
+ +p+nPp
pPpN Pb+ 
R Bq+rK 
Exactly. I would just add that those $, ", %, ( characters which you have removed were the border of the diagram.
tvrzsky
Posts: 128
Joined: Sat Sep 23, 2006 7:10 pm
Location: Prague

Re: writing a word document with diagrams

Post by tvrzsky »

Uri Blass wrote:Thanks for all the replies.

Unfortunately I still do not understand how to put graphic into a word document or into a pdf file
Well, it is not so trivial task if you do not want to do it manually (in the case of a Word document) or if it is a PDF file.
I want to do it because I want to be able to send by email diagrams inside documents to other people.

I do not understand what is
An image using the PNG (Portable Network Graphics) format.

It is going to be productive if somebody explain me exactly what the computer does when it copy a diagram from some site to word document by copy and paste.

What is exactly the content of the thing that the computer copy and how can I develop a program that generates it.
Now it is important to know how often would you do it and take decision whether is it worth your effort and time to learn something about it. What is bitmap or vector graphic or how to create a digram using some chess font designated for it, eventually basics of Postscript programming if you choose this way.
It is not important if it is pdf file or word file and the only important thing is that people are going to be able to get it without buying some new software.
Then I would prefere PDF format.
I would like simply to copy some text file that is going to give me a diagram so I may later write a program that generate text file that if you copy it give you set of diagrams.
I am sorry but I am afraid I do not understand exactly what do you want to do. Please explain it more plainly.
When I look at .ps file with some text editor it is not clear to me and they clearly have more than one diagram.
It is not clear to me exactly what I need to generate a single diagram
and I want to start by seeing code to generate empty diagram with no pieces or diagrams with a single piece(no diagram with many pieces)

I see a diagram with many pieces when the part of the .ps file is probably the following part that I understand nothing from it.

() show 90 zalom
/wdth 90.000000 def
.84 (!""""""""#) /ChessMerida NastavFont
(!""""""""#) prndl
($t+ WlV T%) prndl
($Oo+m+oOo%) prndl
($ +o+ M +%) prndl
($+ +oO +v%) prndl
($ + +p+ +%) prndl
($+ +p+nPp%) prndl
($pPpN Pb+%) prndl
($R Bq+rK %) prndl
(/\(\(\(\(\(\(\(\(\)) prndl
0 vel_d rmoveto
20 zalom
MainFont setfont
( Rybka: 8. ... bf8-e7 -6) prnl
() prnl
()currentrgbcolor .97 0 0 setrgbcolor currentpoint 125 49 rmoveto currentfont 5 scalefont setfont (33) show moveto setrgbcolor MainFont setfont
() prnl
If you want to start with Postscript then have a look at this:
http://en.wikipedia.org/wiki/PostScript
http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF
Then install Ghostscript and GSview in order to be able to view .ps files and toy with Bluebook tutorial. I think that maybe in a week or two you should know enough to understand what is going on in my game.ps file and to be able to create your own scripts according to your exact needs.
As the next example there is the following script which generates just one empty board with pretty blue arrow as a bonus. Procedure for printing arrows has been copied from the forementioned Bluebook. I hope you will like it, it looks like this:
http://tvrzsky.ic.cz/files/arrow.pdf

Code: Select all

/arrowdict 14 dict def
arrowdict begin
 /mtrx matrix def
end

/arrow
{ arrowdict begin
/headlength exch def
/halfheadthickness exch 2 div def
/halfthickness exch 2 div def
/tipy exch def /tipx exch def
/taily exch def /tailx exch def
/dx tipx tailx sub def
/dy tipy taily sub def
/arrowlength dx dx mul dy dy mul add sqrt def
/angle dy dx atan def
/base arrowlength headlength sub def
/savematrix mtrx currentmatrix def
tailx taily translate
angle rotate
0 halfthickness neg moveto
base halfthickness neg lineto
base halfheadthickness neg lineto
arrowlength 0 lineto
base halfheadthickness lineto
base halfthickness lineto
0 halfthickness lineto
closepath
savematrix setmatrix
end
} def

/vel 6 def 
/MainFont 
 /Courier findfont vel scalefont def 
/levy 20 def 
/vert 820 def 
/currleft levy def 
MainFont setfont 
/tabwdth 5 vel mul def 
/zalom { currentpoint 3 -1 roll lt { 310 lt { 310 dup /currleft exch def vert moveto } { showpage levy dup /currleft exch def vert moveto } ifelse } { pop } ifelse } def 
/prnl {show currentpoint pop neg currleft add vel neg rmoveto 20 zalom } def 
/tab { currentpoint pop currleft sub tabwdth div dup 1 add floor exch sub tabwdth mul 0 rmoveto } def 
levy vert moveto 
/wdth 80 def 
/NastavFont { findfont dup 1 scalefont setfont 3 1 roll stringwidth pop mul wdth exch div /vel_d exch def vel_d scalefont setfont } def 
/prndl {dup show stringwidth pop neg vel_d neg rmoveto } def 
gsave 
/wdth 150.000000 def 
110.000000 285.000000 
.84 (!""""""""#) /ChessMerida NastavFont 
moveto 
(!""""""""#) prndl 
($ + + + +%) prndl 
($+ + + + %) prndl 
($ + + + +%) prndl 
($+ + + + %) prndl 
($ + + + +%) prndl 
($+ + + + %) prndl 
($ + + + +%) prndl 
($+ + + + %) prndl 
(/\(\(\(\(\(\(\(\(\)) prndl 
 0 vel_d rmoveto 
grestore 
20 zalom
0 0 1 setrgbcolor
newpath
135 259 245 150 4 12 23 arrow
fill
showpage
Of course feel free to ask another questions.
Filip