Hello list
I've been working on a little project of mine. I give calligraphy workshops
and I have been using a nice tool created by Josselin Cuette, available at
http://ductus.josselincuette.com/ to generate practice templates for
interested people.

However, I would prefer to have an offline solution. This adventure started
with the usual insidious idea: "I could do this in ConTeXt! And this is a
great opportunity to learn metafun!"

A couple weeks later, I have an almost ready product! It compiles fine, but
I have the following issue: The template creates a Line, composed of
Sections. And uses variables to assign a measurement for the nib-width, and
an amount of ascender, x-height and descender Sections (nib-widths), to
compose a Line.

But also, I would like to, if needed, display nib-width marks on the left
side. My code so far generates marks, but only for the first Line. I think
they are generated but maybe they are placed on top of each other, maybe?
I'm not sure why my logic is not working.

Also, if I change the amount for ascenders, descenders of x-height, the
marks are not drawn correctly.

My current path for a mark is a custom path emulating two unit squares,
nib-width size, on top of each other, with the top one shifted a nib-width
to the right. A little bit like a chess board, or a scale ruler on a map.
But this would only work in Lines that have an even amount of Sections. I'm
not sure how to proceed with that... I tried using unit squares, but that
made things very complex, and after fumbling around I managed to get this
far.

If you can take a look, or have some advice, it would be greatly
appreciated. I hope it is understandable.

My code:

%%%%%%%%%%%%%%%%%%
\setuppapersize[letter,landscape][letter,landscape]
\setuplayout[backspace=15mm,width=250mm,header=0mm,footer=0mm]

\startreusableMPgraphic{pauta}
  % Global variables:

  % Show nib-width marks
  boolean marks ; marks := true ;

  % Path for nib-width
  path mark ; mark := (0,0) -- (1,0) -- (1,2) -- (2,2) -- (2,1) -- (0,1) --
cycle ;

  % Line width
  numeric line ; line := \the\textwidth ;

  % Type box
  numeric box ; box := \the\textheight ;

  % Nib width (distance between lines)
  numeric nib ; nib := 3mm ;

  % Ascenders for writing line
  numeric asc ; asc := 3 ;

  % x-height for writing line
  numeric med ; med := 4 ;

  % Descenders for writing line
  numeric dsc ; dsc := 3 ;

  % Total height of a writing line in mm (including asc, med, and dsc)
  numeric lineHeight ;
  lineHeight = (asc + med + dsc) * nib ;

  % Available lines on a page
  numeric availableLines ;
  availableLines = round(box / lineHeight) - 1 ;

  % Starting position
  numeric start ; start := 0 ;

  % Macros

  % Draw a section of a line (ascender, x-height or descender)
  vardef Section(expr lines, initial) =
    draw (0, initial) -- (line, initial) withpen pencircle scaled 0.2mm ;
    for i=0 step 1 until lines :
      save final ; final = i*nib ;
      pair a; a = (0, final + initial) ;
      pair b; b = (line, final + initial) ;
      draw a -- b withpen pencircle scaled 0.1mm ;
      % If marks=true show nib-width marks
      if marks = true:
        fill mark scaled nib yshifted (final*2) ;
      fi ;
    endfor ;
      draw (0, final + initial) -- (line, final + initial)
        withpen pencircle scaled 0.2mm ;
    final + initial
  enddef ;

  % Draw a line with the three secions (asc, med, dsc)
  vardef Line(expr descender, ascender, xheight, initial) =
    numeric dd, oo, aa ;
    % Líneas
    dd = Section(descender, initial) ;
    oo = Section(xheight, dd) ;
    aa = Section(ascender, oo) ;
    % Devolver posicion final con espacio para siguiente renglon
    aa + nib*2
  enddef ;

  % Llenar la página con renglones
  for i=1 upto availableLines :
    start := Line(dsc, asc, med, start) ;
  endfor ;
\stopreusableMPgraphic

\startdocument
  \startstandardmakeup
    \reuseMPgraphic{pauta}
  \stopstandardmakeup
\stopdocument
%%%%%%%%%%%%%%%%%%%%%%%%%%

-- 
Andrés Conrado Montoya
Andi Kú
andresconr...@gmail.com
http://sesentaycuatro.com
http://messier87.com
http://chiquitico.org
----------------------------------------
Los fines no justifican los medios, porque la medida verdadera de nuestro
carácter está dada por los medios que estamos dispuestos a utilizar, no por
los fines que proclamamos.
----------------------------------------

“You develop an instant global consciousness, a people orientation, an
intense dissatisfaction with the state of the world, and a compulsion to do
something about it. From out there on the moon, international politics look
so petty. You want to grab a politician by the scruff of the neck and drag
him a quarter of a million miles out and say, ‘Look at that, you son of a
bitch.’” — Apollo 14 astronaut Edgar Mitchell
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to