예제 #1
0
docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const & op) const
{
	docstring const & ref = getParam("reference");
	InsetLabel const * il = buffer().insetLabel(ref);
	string const & cmd = params().getCmdName();
	docstring display_string;

	if (il && !il->counterValue().empty()) {
		// Try to construct a label from the InsetLabel we reference.
		docstring const & value = il->counterValue();
		if (cmd == "ref")
			display_string = value;
		else if (cmd == "vref")
			// normally, would be "ref on page #", but we have no pages
			display_string = value;
		else if (cmd == "pageref" || cmd == "vpageref")
			// normally would be "on page #", but we have no pages.
			display_string = translateIfPossible(from_ascii("elsewhere"),
			        op.local_font->language()->lang());
		else if (cmd == "eqref")
			display_string = '(' + value + ')';
		else if (cmd == "formatted")
			display_string = il->prettyCounter();
		else if (cmd == "nameref")
			// FIXME We don't really have the ability to handle these
			// properly in XHTML output yet (bug #8599).
			// It might not be that hard to do. We have the InsetLabel,
			// and we can presumably find its paragraph using the TOC.
			// We could then output the contents of the paragraph using
			// something?
			display_string = il->prettyCounter();
	} else 
			display_string = ref;

	// FIXME What we'd really like to do is to be able to output some
	// appropriate sort of text here. But to do that, we need to associate
	// some sort of counter with the label, and we don't have that yet.
	string const attr = "href=\"#" + html::cleanAttr(to_utf8(ref)) + "\"";
	xs << html::StartTag("a", attr);
	xs << display_string;
	xs << html::EndTag("a");
	return docstring();
}
예제 #2
0
docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const
{
	if (rp.html_disable_captions)
		return docstring();
	InsetLayout const & il = getLayout();
	string const & tag = il.htmltag();
	string attr = il.htmlattr();
	if (!type_.empty()) {
		string const our_class = "float-caption-" + type_;
		size_t const loc = attr.find("class='");
		if (loc != string::npos)
			attr.insert(loc + 7, our_class + " ");
		else
			attr = attr + " class='" + our_class + "'";
	}
	xs << html::StartTag(tag, attr);
	docstring def = getCaptionAsHTML(xs, rp);
	xs << html::EndTag(tag);
	return def;
}
예제 #3
0
docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const
{
	switch (kind_) {
	case HYPHENATION:
		break;
	case ALLOWBREAK:
		xs << XHTMLStream::ESCAPE_NONE << "&#8203;";
		break;
	case LIGATURE_BREAK:
		xs << XHTMLStream::ESCAPE_NONE << "&#8204;";
		break;
	case END_OF_SENTENCE:
		xs << '.';
		break;
	case LDOTS:
		xs << XHTMLStream::ESCAPE_NONE << "&hellip;";
		break;
	case MENU_SEPARATOR:
		xs << XHTMLStream::ESCAPE_NONE << "&rArr;";
		break;
	case SLASH:
		xs << XHTMLStream::ESCAPE_NONE << "&frasl;";
		break;
	case NOBREAKDASH:
		xs << XHTMLStream::ESCAPE_NONE << "&#8209;";
		break;
	case PHRASE_LYX:
		xs << "LyX";
		break;
	case PHRASE_TEX:
		xs << "TeX";
		break;
	case PHRASE_LATEX2E:
		xs << "LaTeX2" << XHTMLStream::ESCAPE_NONE << "&#x3b5;";
		break;
	case PHRASE_LATEX:
		xs << "LaTeX";
		break;
	}
	return docstring();
}
예제 #4
0
docstring InsetPrintNomencl::xhtml(XHTMLStream &, OutputParams const &) const
{
	return docstring();
}
예제 #5
0
int main(int argc, char **argv) {
  char *ai, *fname;
  char flamename[256];
  char *prefix = args("prefix", "");
  int first_frame = argi("begin", 0);
  int last_frame = argi("end", 0);
  int frame_time = argi("time", 0);
  int dtime = argi("dtime", 1);
  int do_fields = argi("fields", 0);
  int write_genome = argi("write_genome",0);
  double qs = argf("qs", 1.0);
  double ss = argf("ss", 1.0);
  char *format = getenv("format");
  int verbose = argi("verbose", 1);
  int transparency = argi("transparency", 0);
  int bits = argi("bits", 33);
  int sub_batch_size = argi("sub_batch_size", 10000);
  int bpc = argi("bpc",8);
  int earlyclip = argi("earlyclip",0);
  int ftime, channels;
  unsigned char *image;
  flam3_genome *cps,center_cp;
  int i, ncps = 0;
  char *inf = getenv("in");
  double pixel_aspect = argf("pixel_aspect", 1.0);
  int num_threads = argi("nthreads",0);
  FILE *in,*fp,*genfp;
  flam3_frame f;
  flam3_img_comments fpc;
  stat_struct stats,stats2;

  char badval_string[64];
  char numiter_string[64];
  char rtime_string[64];
  
#ifdef WIN32
   
  char *slashloc;
  char exepath[256];
  char palpath[256];
  memset(exepath,0,256);
  memset(palpath,0,256);  
   slashloc = strrchr(argv[0],'\\');
	if (NULL==slashloc) {
	   sprintf(palpath,"flam3_palettes=flam3-palettes.xml");
	} else {
       strncpy(exepath,argv[0],slashloc-argv[0]+1);
	   sprintf(palpath,"flam3_palettes=%sflam3-palettes.xml",exepath);
	}
	putenv(palpath);

#endif         
  
  
  memset(&center_cp,0, sizeof(flam3_genome));

  if (1 != argc) {
      docstring();
      exit(0);
  }

   /* Init random number generators */
   flam3_init_frame(&f);
   flam3_srandom();

   /* Set the number of threads */
   if (num_threads==0) {
      num_threads = flam3_count_nthreads();
      if (verbose > 1)
         fprintf(stderr,"Automatically detected %d core(s)...\n",num_threads);
   } else{
      if (verbose)
         fprintf(stderr,"Manually specified %d thread(s)...\n",num_threads);
   }

  if (getenv("frame")) {
    if (getenv("time")) {
      fprintf(stderr, "cannot specify both time and frame.\n");
      exit(1);
    }
    if (getenv("begin") || getenv("end")) {
      fprintf(stderr, "cannot specify both frame and begin or end.\n");
      exit(1);
    }
    first_frame = last_frame = atoi(getenv("frame"));
  }

  if (getenv("time")) {
    if (getenv("begin") || getenv("end")) {
      fprintf(stderr, "cannot specify both time and begin or end.\n");
      exit(1);
    }
    first_frame = last_frame = frame_time;
  }

  if (NULL == format) format = "png";
  if (strcmp(format, "jpg") &&
      strcmp(format, "ppm") &&
      strcmp(format, "png")) {
      fprintf(stderr, "format must be either jpg, ppm, or png, not %s.\n", format);
      exit(1);
  }


   if (pixel_aspect <= 0.0) {
     fprintf(stderr, "pixel aspect ratio must be positive, not %g.\n",
        pixel_aspect);
     exit(1);
   }

  if (inf)
    in = fopen(inf, "rb");
  else
    in = stdin;
  if (NULL == in) {
    perror(inf);
    exit(1);
  }

  cps = flam3_parse_from_file(in, inf, flam3_defaults_on, &ncps);
  if (inf)
    fclose(in);
  if (NULL == cps) {
    fprintf(stderr," error reading genomes.\n");
    exit(1);
  }
  if (0 == ncps) {
    fprintf(stderr, "error: no genomes.\n");
    exit(1);
  }
  for (i = 0; i < ncps; i++) {
    cps[i].sample_density *= qs;
    cps[i].height = (int)(cps[i].height * ss);
    cps[i].width = (int)(cps[i].width * ss);
    cps[i].pixels_per_unit *= ss;
    if (cps[i].height<=0 || cps[i].width<=0) {
       fprintf(stderr,"output image has dimension <=0, aborting.\n");
       exit(1);
    }
    if (i > 0 && cps[i].time <= cps[i-1].time) {
   fprintf(stderr, "error: control points must be sorted by time, but %g <= %g, index %d.\n",
      cps[i].time, cps[i-1].time, i);
   exit(1);
    }
    if ((cps[i].width != cps[0].width) ||
   (cps[i].height != cps[0].height)) {
      fprintf(stderr, "warning: flame %d at time %g size mismatch.  "
         "(%d,%d) should be (%d,%d).\n",
         i, cps[i].time,
         cps[i].width, cps[i].height,
         cps[0].width, cps[0].height);
      cps[i].width = cps[0].width;
      cps[i].height = cps[0].height;
    }
  }
  if (!getenv("time") && !getenv("frame")) {
    if (!getenv("begin")) {
      first_frame = (int) cps[0].time;
    }
    if (!getenv("end")) {
      last_frame = (int) cps[ncps-1].time - 1;
      if (last_frame < first_frame) last_frame = first_frame;
    }
  }
  channels = strcmp(format, "png") ? 3 : 4;

   /* Check for 16-bit-per-channel processing */
   if ( (16 == bpc) && (strcmp(format,"png") != 0)) {
	fprintf(stderr,"Support for 16 bpc images is only present for the png format.\n");
	exit(1);
   } else if (bpc != 8 && bpc != 16) {
	fprintf(stderr,"Unexpected bpc specified (%d)\n",bpc);
	exit(1);
   }
   
//  f.temporal_filter_radius = argf("blur", 0.5);
  f.pixel_aspect_ratio = pixel_aspect;
  f.genomes = cps;
  f.ngenomes = ncps;
  f.verbose = verbose;
  f.bits = bits;
  f.progress = 0;
  f.earlyclip = earlyclip;
  f.nthreads = num_threads;
  f.sub_batch_size = sub_batch_size;

  if (16==bpc)
     f.bytes_per_channel = 2;
  else
     f.bytes_per_channel = 1;
         

  image = (void *) calloc((size_t)channels *
				   (size_t)cps[0].width *
				   (size_t)cps[0].height * f.bytes_per_channel, sizeof(char));

  if (dtime < 1) {
    fprintf(stderr, "dtime must be positive, not %d.\n", dtime);
    exit(1);
  }

  for (ftime = first_frame; ftime <= last_frame; ftime += dtime) {
    f.time = (double) ftime;

    if (verbose && ((last_frame-first_frame)/dtime) >= 1) {
       fprintf(stderr, "time = %d/%d/%d\n", ftime, last_frame, dtime);
    }

    if (do_fields) {
    
   if (flam3_render(&f, image, flam3_field_even, channels, transparency,&stats)) {
      fprintf(stderr,"error rendering image: aborting.\n");
      exit(1);
   }
   f.time += 0.5;
   if (flam3_render(&f, image, flam3_field_odd, channels, transparency,&stats2)) {
      fprintf(stderr,"error rendering image: aborting.\n");
      exit(1);
   }

   stats.badvals+=stats2.badvals;
   stats.render_seconds+=stats2.render_seconds;
   stats.num_iters+=stats2.num_iters;
    } else {
   if (flam3_render(&f, image, flam3_field_both, channels, transparency,&stats)) {
      fprintf(stderr,"error rendering image: aborting.\n");
      exit(1);
   }
    }

    if (getenv("out"))
       fname = getenv("out");
    else {
       fname = malloc(strlen(prefix) + 20);
       sprintf(fname, "%s%05d.%s", prefix, ftime, format);
    }

    if (verbose)
       fprintf(stderr, "writing %s...", fname);

    if (write_genome) {
       sprintf(flamename,"%s.flam3",fname);
   
       /* get center genome */
       flam3_interpolate(f.genomes, f.ngenomes, f.time, 0, &center_cp);
       
       /* write it out */
       genfp = fopen(flamename,"w");
       if (NULL == genfp) {
           perror(flamename);
           exit(1);
       }
       
       flam3_print(genfp, &center_cp, NULL, flam3_print_edits);
       
       fclose(genfp);
    }

    fp = fopen(fname, "wb");
    if (NULL == fp) {
       perror(fname);
       exit(1);
    }

    /* Get center cp for embedding in png file */
    flam3_interpolate(f.genomes, f.ngenomes, f.time, 0, &center_cp);
   
    /* Convert to string */
    fpc.genome = flam3_print_to_string(&center_cp);      
    sprintf(badval_string, "%g",stats.badvals/(double)stats.num_iters);
    fpc.badvals = badval_string;
    sprintf(numiter_string,"%g",(double)stats.num_iters);
    fpc.numiters = numiter_string;
    sprintf(rtime_string,"%d",stats.render_seconds);
    fpc.rtime = rtime_string;
   
    if (!strcmp(format, "png")) {
    
       write_png(fp, image, cps[0].width, cps[0].height, &fpc, f.bytes_per_channel);       
       
    } else if (!strcmp(format, "jpg")) {
    
       write_jpeg(fp, image, cps[0].width, cps[0].height, &fpc);

    } else {
	int size = 3 * cps[0].width * cps[0].height;
       fprintf(fp, "P6\n");
       fprintf(fp, "%d %d\n255\n", cps[0].width, cps[0].height);
       if (size != fwrite(image, 1, size, fp)) {
	   perror(fname);
       }
    }

    /* Free string */
    free(fpc.genome);
    
    clear_cp(&center_cp,0);

    fclose(fp);

    if (!getenv("out"))
       free(fname);

  }
  
  for (i = 0; i < ncps; i++) {
     xmlFreeDoc(cps[i].edits);
     clear_cp(&cps[i],0);
  }
  free(cps);

  free(image);
  
  if (verbose)
    fprintf(stderr, "done.\n");

  fflush(stderr);
  return 0;
}
예제 #6
0
docstring Inset::completionPrefix(Cursor const &) const 
{
	return docstring();
}
예제 #7
0
	InsetName(string const & n = string(), docstring const & dn = docstring())
		: name(n), display_name(dn) {}
예제 #8
0
docstring Inset::xhtml(XHTMLStream & xs, OutputParams const &) const
{
	xs << "[[Inset: " << from_ascii(insetName(lyxCode())) << "]]";
	return docstring();
}
예제 #9
0
파일: InsetTOC.cpp 프로젝트: bsjung/Lyx
docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
{
	Layout const & lay = buffer().params().documentClass().htmlTOCLayout();
	string const & tocclass = lay.defaultCSSClass();
	string const tocattr = "class='tochead " + tocclass + "'";
	
	// we'll use our own stream, because we are going to defer everything.
	// that's how we deal with the fact that we're probably inside a standard
	// paragraph, and we don't want to be.
	odocstringstream ods;
	XHTMLStream xs(ods);

	Toc const & toc = buffer().tocBackend().toc("tableofcontents");
	if (toc.empty())
		return docstring();

	xs << html::StartTag("div", "class='toc'");

	// Title of TOC
	Language const * lang = buffer().params().language;
	static string toctitle = N_("Table of Contents");
	docstring title = lang 
			? translateIfPossible(from_ascii(toctitle), lang->code())
			: translateIfPossible(from_ascii(toctitle));
	xs << html::StartTag("div", tocattr)
		 << title
		 << html::EndTag("div");

	// Output of TOC
	Toc::const_iterator it = toc.begin();
	Toc::const_iterator const en = toc.end();
	int lastdepth = 0;
	for (; it != en; ++it) {
		// First, we need to manage increases and decreases of depth
		int const depth = it->depth();
		
		// Ignore stuff above the tocdepth
		if (depth > buffer().params().tocdepth)
			continue;
		
		if (depth > lastdepth) {
			xs.cr();
			// open as many tags as we need to open to get to this level
			// this includes the tag for the current level
			for (int i = lastdepth + 1; i <= depth; ++i) {
				stringstream attr;
				attr << "class='lyxtoc-" << i << "'";
				xs << html::StartTag("div", attr.str());
			}
			lastdepth = depth;
		}
		else if (depth < lastdepth) {
			// close as many as we have to close to get back to this level
			// this includes closing the last tag at this level
			for (int i = lastdepth; i >= depth; --i) 
				xs << html::EndTag("div");
			// now open our tag
			stringstream attr;
			attr << "class='lyxtoc-" << depth << "'";
			xs << html::StartTag("div", attr.str());
			lastdepth = depth;
		} else {
			// no change of level, so close and open
			xs << html::EndTag("div");
			stringstream attr;
			attr << "class='lyxtoc-" << depth << "'";
			xs << html::StartTag("div", attr.str());
		}
		
		// Now output TOC info for this entry
		Paragraph const & par = it->dit().innerParagraph();
		// First the label, if there is one
		docstring const & label = par.params().labelString();
		if (!label.empty())
			xs << label << " ";
		// Now the content of the TOC entry, taken from the paragraph itself
		OutputParams ours = op;
		ours.for_toc = true;
		Font const dummy;
		par.simpleLyXHTMLOnePar(buffer(), xs, ours, dummy);
		xs << " ";
		// Now a link to that paragraph
		string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'";
		xs << html::StartTag("a", parattr);
		// FIXME XHTML 
		// There ought to be a simple way to customize this.
		// Maybe if we had an InsetLayout for TOC...
		xs << XHTMLStream::NextRaw() << "&gt;";
		xs << html::EndTag("a");		
	}
	for (int i = lastdepth; i > 0; --i) 
		xs << html::EndTag("div");
	xs << html::EndTag("div");
	return ods.str();
}
예제 #10
0
void InsetMathString::write(WriteStream & os) const
{
	if (!os.latex() || os.lockedMode()) {
		os << (os.asciiOnly() ? escape(str_) : str_);
		return;
	}

	docstring::const_iterator cit = str_.begin();
	docstring::const_iterator end = str_.end();

	// We may already be inside an \ensuremath command.
	bool in_forced_mode = os.pendingBrace();

	// We will take care of matching braces.
	os.pendingBrace(false);

	while (cit != end) {
		bool mathmode = in_forced_mode ? os.textMode() : !os.textMode();
		char_type const c = *cit;
		docstring command(1, c);
		try {
			bool termination = false;
			if (isASCII(c) ||
			    Encodings::latexMathChar(c, mathmode, os.encoding(), command, termination)) {
				if (os.textMode()) {
					if (in_forced_mode) {
						// we were inside \lyxmathsym
						os << '}';
						os.textMode(false);
						in_forced_mode = false;
					}
					if (!isASCII(c) && os.textMode()) {
						os << "\\ensuremath{";
						os.textMode(false);
						in_forced_mode = true;
					}
				} else if (isASCII(c) && in_forced_mode) {
					// we were inside \ensuremath
					os << '}';
					os.textMode(true);
					in_forced_mode = false;
				}
			} else if (!os.textMode()) {
					if (in_forced_mode) {
						// we were inside \ensuremath
						os << '}';
						in_forced_mode = false;
					} else {
						os << "\\lyxmathsym{";
						in_forced_mode = true;
					}
					os.textMode(true);
			}
			os << command;
			// We may need a space if the command contains a macro
			// and the last char is ASCII.
			if (termination)
				os.pendingSpace(true);
		} catch (EncodingException const & e) {
			switch (os.output()) {
			case WriteStream::wsDryrun: {
				os << "<" << _("LyX Warning: ")
				   << _("uncodable character") << " '";
				os << docstring(1, e.failed_char);
				os << "'>";
				break;
			}
			case WriteStream::wsPreview: {
				// indicate the encoding error by a boxed '?'
				os << "{\\fboxsep=1pt\\fbox{?}}";
				LYXERR0("Uncodable character" << " '"
					<< docstring(1, e.failed_char)
					<< "'");
				break;
			}
			case WriteStream::wsDefault:
			default:
				// throw again
				throw(e);
			}
		}
		++cit;
	}

	if (in_forced_mode && os.textMode()) {
		// We have to care for closing \lyxmathsym
		os << '}';
		os.textMode(false);
	} else {
		os.pendingBrace(in_forced_mode);
	}
}
예제 #11
0
void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
{
	string param_string = params().params();
	// NOTE: I use {} to quote text, which is an experimental feature
	// of the listings package (see page 25 of the manual)
	bool const isInline = params().isInline();
	// get the paragraphs. We can not output them directly to given odocstream
	// because we can not yet determine the delimiter character of \lstinline
	docstring code;
	docstring uncodable;
	ParagraphList::const_iterator par = paragraphs().begin();
	ParagraphList::const_iterator end = paragraphs().end();

	bool encoding_switched = false;
	Encoding const * const save_enc = runparams.encoding;

	if (!runparams.isFullUnicode()
	    && !runparams.encoding->hasFixedWidth()) {
		// We need to switch to a singlebyte encoding, since the
		// listings package cannot deal with multi-byte-encoded
		// glyphs (not needed with full-unicode aware backends
		// such as XeTeX).
		Language const * const outer_language =
			(runparams.local_font != 0) ?
				runparams.local_font->language()
				: buffer().params().language;
		// We try if there's a singlebyte encoding for the current
		// language; if not, fall back to latin1.
		Encoding const * const lstenc =
			(outer_language->encoding()->hasFixedWidth()) ?
				outer_language->encoding() 
				: encodings.fromLyXName("iso8859-1");
		switchEncoding(os.os(), buffer().params(), runparams, *lstenc, true);
		runparams.encoding = lstenc;
		encoding_switched = true;
	}

	while (par != end) {
		pos_type siz = par->size();
		bool captionline = false;
		for (pos_type i = 0; i < siz; ++i) {
			if (i == 0 && par->isInset(i) && i + 1 == siz)
				captionline = true;
			// ignore all struck out text and (caption) insets
			if (par->isDeleted(i) || par->isInset(i))
				continue;
			char_type c = par->getChar(i);
			// we can only output characters covered by the current
			// encoding!
			try {
				if (runparams.encoding->encodable(c))
					code += c;
				else if (runparams.dryrun) {
					code += "<" + _("LyX Warning: ")
					   + _("uncodable character") + " '";
					code += docstring(1, c);
					code += "'>";
 				} else
					uncodable += c;
			} catch (EncodingException & /* e */) {
 				if (runparams.dryrun) {
					code += "<" + _("LyX Warning: ")
					   + _("uncodable character") + " '";
					code += docstring(1, c);
					code += "'>";
 				} else
					uncodable += c;
			}
		}
		++par;
		// for the inline case, if there are multiple paragraphs
		// they are simply joined. Otherwise, expect latex errors.
		if (par != end && !isInline && !captionline)
			code += "\n";
	}
	if (isInline) {
		char const * delimiter = lstinline_delimiters;
		for (; delimiter != '\0'; ++delimiter)
			if (!contains(code, *delimiter))
				break;
		// This code piece contains all possible special character? !!!
		// Replace ! with a warning message and use ! as delimiter.
		if (*delimiter == '\0') {
			docstring delim_error = "<" + _("LyX Warning: ")
				+ _("no more lstline delimiters available") + ">";
			code = subst(code, from_ascii("!"), delim_error);
			delimiter = lstinline_delimiters;
			if (!runparams.dryrun) {
				// FIXME: warning should be passed to the error dialog
				frontend::Alert::warning(_("Running out of delimiters"),
				_("For inline program listings, one character must be reserved\n"
				  "as a delimiter. One of the listings, however, uses all available\n"
				  "characters, so none is left for delimiting purposes.\n"
				  "For the time being, I have replaced '!' by a warning, but you\n"
				  "must investigate!"));
			}
		}
		if (param_string.empty())
			os << "\\lstinline" << *delimiter;
		else
			os << "\\lstinline[" << from_utf8(param_string) << "]" << *delimiter;
                os << code
                   << *delimiter;
	} else {
		OutputParams rp = runparams;
		rp.moving_arg = true;
		docstring const caption = getCaption(rp);
		if (param_string.empty() && caption.empty())
			os << breakln << "\\begin{lstlisting}\n";
		else {
			os << breakln << "\\begin{lstlisting}[";
			if (!caption.empty()) {
				os << "caption={" << caption << '}';
				if (!param_string.empty())
					os << ',';
			}
			os << from_utf8(param_string) << "]\n";
		}
		os << code << breakln << "\\end{lstlisting}\n";
	}

	if (encoding_switched){
		// Switch back
		switchEncoding(os.os(), buffer().params(), runparams, *save_enc, true);
		runparams.encoding = save_enc;
	}

	if (!uncodable.empty()) {
		// issue a warning about omitted characters
		// FIXME: should be passed to the error dialog
		frontend::Alert::warning(_("Uncodable characters in listings inset"),
			bformat(_("The following characters in one of the program listings are\n"
				  "not representable in the current encoding and have been omitted:\n%1$s."),
			uncodable));
	}
}
docstring const AppleSpellChecker::error()
{
	return docstring();
}
예제 #13
0
파일: Parser.cpp 프로젝트: cburschka/lyx
void Parser::tokenize_one()
{
	catInit();
	char_type c;
	if (!is_.get(c))
		return;

	switch (catcode(c)) {
	case catSpace: {
		docstring s(1, c);
		while (is_.get(c) && catcode(c) == catSpace)
			s += c;
		if (catcode(c) != catSpace)
			is_.putback(c);
		push_back(Token(s, catSpace));
		break;
	}

	case catNewline: {
		++lineno_;
		docstring s(1, getNewline(is_, c));
		while (is_.get(c) && catcode(c) == catNewline) {
			++lineno_;
			s += getNewline(is_, c);
		}
		if (catcode(c) != catNewline)
			is_.putback(c);
		push_back(Token(s, catNewline));
		break;
	}

	case catComment: {
		// We don't treat "%\n" combinations here specially because
		// we want to preserve them in the preamble
		docstring s;
		while (is_.get(c) && catcode(c) != catNewline)
			s += c;
		// handle possible DOS line ending
		if (catcode(c) == catNewline)
			c = getNewline(is_, c);
		// Note: The '%' at the beginning and the '\n' at the end
		// of the comment are not stored.
		++lineno_;
		push_back(Token(s, catComment));
		break;
	}

	case catEscape: {
		is_.get(c);
		if (!is_) {
			error("unexpected end of input");
		} else {
			docstring s(1, c);
			if (catcode(c) == catLetter) {
				// collect letters
				while (is_.get(c) && catcode(c) == catLetter)
					s += c;
				if (catcode(c) != catLetter)
					is_.putback(c);
			}
			push_back(Token(s, catEscape));
		}
		break;
	}

	case catIgnore: {
		cerr << "ignoring a char: " << c << "\n";
		break;
	}

	default:
		push_back(Token(docstring(1, c), catcode(c)));
	}
	//cerr << tokens_.back();
}
예제 #14
0
docstring InsetArgument::xhtml(XHTMLStream &, OutputParams const &) const
{
	return docstring();
}
예제 #15
0
docstring const EnchantChecker::error()
{
	return docstring();
}
예제 #16
0
docstring Inset::toolTip(BufferView const &, int, int) const
{
	return docstring();
}
예제 #17
0
void writePlaintextParagraph(Buffer const & buf,
                             Paragraph const & par,
                             odocstream & os,
                             OutputParams const & runparams,
                             bool & ref_printed)
{
    int ltype = 0;
    depth_type ltype_depth = 0;
    depth_type depth = par.params().depth();

    // First write the layout
    string const tmp = to_utf8(par.layout().name());
    if (compare_ascii_no_case(tmp, "itemize") == 0) {
        ltype = 1;
        ltype_depth = depth + 1;
    } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
        ltype = 2;
        ltype_depth = depth + 1;
    } else if (contains(ascii_lowercase(tmp), "ection")) {
        ltype = 3;
        ltype_depth = depth + 1;
    } else if (contains(ascii_lowercase(tmp), "aragraph")) {
        ltype = 4;
        ltype_depth = depth + 1;
    } else if (compare_ascii_no_case(tmp, "description") == 0) {
        ltype = 5;
        ltype_depth = depth + 1;
    } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
        ltype = 6;
        ltype_depth = 0;
    } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
        ltype = 7;
        ltype_depth = 0;
    } else {
        ltype = 0;
        ltype_depth = 0;
    }

    /* the labelwidthstring used in lists */

    /* noindent ? */

    /* what about the alignment */

    // runparams.linelen == 0 is special and means we don't have paragraph breaks

    string::size_type currlinelen = 0;

    os << docstring(depth * 2, ' ');
    currlinelen += depth * 2;

    //--
    // we should probably change to the paragraph language in the
    // support/gettext.here (if possible) so that strings are output in
    // the correct language! (20012712 Jug)
    //--
    switch (ltype) {
    case 0: // Standard
    case 4: // (Sub)Paragraph
    case 5: // Description
        break;

    case 6: // Abstract
        if (runparams.linelen > 0) {
            os << buf.B_("Abstract") << "\n\n";
            currlinelen = 0;
        } else {
            docstring const abst = buf.B_("Abstract: ");
            os << abst;
            currlinelen += abst.length();
        }
        break;

    case 7: // Bibliography
        if (!ref_printed) {
            if (runparams.linelen > 0) {
                os << buf.B_("References") << "\n\n";
                currlinelen = 0;
            } else {
                docstring const refs = buf.B_("References: ");
                os << refs;
                currlinelen += refs.length();
            }
            ref_printed = true;
        }
        break;

    default: {
        docstring const label = par.params().labelString();
        if (!label.empty()) {
            os << label << ' ';
            currlinelen += label.length() + 1;
        }
        break;
    }

    }

    if (currlinelen == 0) {
        pair<int, docstring> p = addDepth(depth, ltype_depth);
        os << p.second;
        currlinelen += p.first;
    }

    docstring word;

    for (pos_type i = 0; i < par.size(); ++i) {
        // deleted characters don't make much sense in plain text output
        if (par.isDeleted(i))
            continue;

        char_type c = par.getUChar(buf.params(), i);

        if (par.isInset(i) || c == ' ') {
            if (runparams.linelen > 0 &&
                    currlinelen + word.length() > runparams.linelen) {
                os << '\n';
                pair<int, docstring> p = addDepth(depth, ltype_depth);
                os << p.second;
                currlinelen = p.first;
            }
            os << word;
            currlinelen += word.length();
            word.erase();
        }

        if (par.isInset(i)) {
            OutputParams rp = runparams;
            rp.depth = par.params().depth();
            int len = par.getInset(i)->plaintext(os, rp);
            if (len >= Inset::PLAINTEXT_NEWLINE)
                currlinelen = len - Inset::PLAINTEXT_NEWLINE;
            else
                currlinelen += len;
            continue;
        }

        switch (c) {
        case ' ':
            os << ' ';
            currlinelen++;
            break;

        case '\0':
            LYXERR(Debug::INFO, "writePlaintextFile: NUL char in structure.");
            break;

        default:
            word += c;
            break;
        }
    }

    // currlinelen may be greater than runparams.linelen!
    // => check whether word is empty and do nothing in this case
    if (!word.empty()) {
        if (runparams.linelen > 0 &&
                currlinelen + word.length() > runparams.linelen) {
            os << '\n';
            pair<int, docstring> p = addDepth(depth, ltype_depth);
            os << p.second;
            currlinelen = p.first;
        }
        os << word;
    }
}
예제 #18
0
docstring InsetCitation::complexLabel(bool for_xhtml) const
{
	Buffer const & buf = buffer();
	// Only start the process off after the buffer is loaded from file.
	if (!buf.isFullyLoaded())
		return docstring();

	BiblioInfo const & biblist = buf.masterBibInfo();
	if (biblist.empty())
		return docstring();

	// the natbib citation-styles
	// CITET:	author (year)
	// CITEP:	(author,year)
	// CITEALT:	author year
	// CITEALP:	author, year
	// CITEAUTHOR:	author
	// CITEYEAR:	year
	// CITEYEARPAR:	(year)
	// jurabib supports these plus
	// CITE:	author/<before field>

	CiteEngine const engine = buffer().params().citeEngine();
	// We don't currently use the full or forceUCase fields.
	string cite_type = asValidLatexCommand(getCmdName(), engine);
	if (cite_type[0] == 'C')
		// If we were going to use them, this would mean ForceUCase
		cite_type = string(1, 'c') + cite_type.substr(1);
	if (cite_type[cite_type.size() - 1] == '*')
		// and this would mean FULL
		cite_type = cite_type.substr(0, cite_type.size() - 1);

	docstring const & before = getParam("before");
	docstring before_str;
	if (!before.empty()) {
		// In CITET and CITEALT mode, the "before" string is
		// attached to the label associated with each and every key.
		// In CITEP, CITEALP and CITEYEARPAR mode, it is attached
		// to the front of the whole only.
		// In other modes, it is not used at all.
		if (cite_type == "citet" ||
		    cite_type == "citealt" ||
		    cite_type == "citep" ||
		    cite_type == "citealp" ||
		    cite_type == "citeyearpar")
			before_str = before + ' ';
		// In CITE (jurabib), the "before" string is used to attach
		// the annotator (of legal texts) to the author(s) of the
		// first reference.
		else if (cite_type == "cite")
			before_str = '/' + before;
	}

	docstring const & after = getParam("after");
	docstring after_str;
	// The "after" key is appended only to the end of the whole.
	if (cite_type == "nocite")
		after_str =  " (" + _("not cited") + ')';
	else if (!after.empty()) {
		after_str = ", " + after;
	}

	// One day, these might be tunable (as they are in BibTeX).
	char op, cp;	// opening and closing parenthesis.
	const char * sep;	// punctuation mark separating citation entries.
	if (engine == ENGINE_BASIC) {
		op  = '[';
		cp  = ']';
		sep = ",";
	} else {
		op  = '(';
		cp  = ')';
		sep = ";";
	}

	docstring const op_str = ' ' + docstring(1, op);
	docstring const cp_str = docstring(1, cp) + ' ';
	docstring const sep_str = from_ascii(sep) + ' ';

	docstring label;
	vector<docstring> keys = getVectorFromString(getParam("key"));
	vector<docstring>::const_iterator it  = keys.begin();
	vector<docstring>::const_iterator end = keys.end();
	for (; it != end; ++it) {
		// get the bibdata corresponding to the key
		docstring const author = biblist.getAbbreviatedAuthor(*it);
		docstring const year = biblist.getYear(*it, for_xhtml);
		docstring const citenum = for_xhtml ? biblist.getCiteNumber(*it) : *it;

		if (author.empty() || year.empty())
			// We can't construct a "complex" label without that info.
			// So fail safely.
			return docstring();

		// authors1/<before>;  ... ;
		//  authors_last, <after>
		if (cite_type == "cite") {
			if (engine == ENGINE_BASIC) {
				label += wrapCitation(*it, citenum, for_xhtml) + sep_str;
			} else if (engine == ENGINE_JURABIB) {
				if (it == keys.begin())
					label += wrapCitation(*it, author, for_xhtml) + before_str + sep_str;
				else
					label += wrapCitation(*it, author, for_xhtml) + sep_str;
			}
		} 
		// nocite
		else if (cite_type == "nocite") {
			label += *it + sep_str;
		} 
		// (authors1 (<before> year);  ... ;
		//  authors_last (<before> year, <after>)
		else if (cite_type == "citet") {
			switch (engine) {
			case ENGINE_NATBIB_AUTHORYEAR:
				label += author + op_str + before_str +
					wrapCitation(*it, year, for_xhtml) + cp + sep_str;
				break;
			case ENGINE_NATBIB_NUMERICAL:
				label += author + op_str + before_str + 
					wrapCitation(*it, citenum, for_xhtml) + cp + sep_str;
				break;
			case ENGINE_JURABIB:
				label += before_str + author + op_str +
					wrapCitation(*it, year, for_xhtml) + cp + sep_str;
				break;
			case ENGINE_BASIC:
				break;
			}
		} 
		// author, year; author, year; ...	
		else if (cite_type == "citep" ||
			   cite_type == "citealp") {
			if (engine == ENGINE_NATBIB_NUMERICAL) {
				label += wrapCitation(*it, citenum, for_xhtml) + sep_str;
			} else {
				label += wrapCitation(*it, author + ", " + year, for_xhtml) + sep_str;
			}

		} 
		// (authors1 <before> year;
		//  authors_last <before> year, <after>)
		else if (cite_type == "citealt") {
			switch (engine) {
			case ENGINE_NATBIB_AUTHORYEAR:
				label += author + ' ' + before_str +
					wrapCitation(*it, year, for_xhtml) + sep_str;
				break;
			case ENGINE_NATBIB_NUMERICAL:
				label += author + ' ' + before_str + '#' + 
					wrapCitation(*it, citenum, for_xhtml) + sep_str;
				break;
			case ENGINE_JURABIB:
				label += before_str + 
					wrapCitation(*it, author + ' ' + year, for_xhtml) + sep_str;
				break;
			case ENGINE_BASIC:
				break;
			}

		
		} 
		// author; author; ...
		else if (cite_type == "citeauthor") {
			label += wrapCitation(*it, author, for_xhtml) + sep_str;
		}
		// year; year; ...
		else if (cite_type == "citeyear" ||
			   cite_type == "citeyearpar") {
			label += wrapCitation(*it, year, for_xhtml) + sep_str;
		}
	}
	label = rtrim(rtrim(label), sep);

	if (!after_str.empty()) {
		if (cite_type == "citet") {
			// insert "after" before last ')'
			label.insert(label.size() - 1, after_str);
		} else {
			bool const add =
				!(engine == ENGINE_NATBIB_NUMERICAL &&
				  (cite_type == "citeauthor" ||
				   cite_type == "citeyear"));
			if (add)
				label += after_str;
		}
	}

	if (!before_str.empty() && (cite_type == "citep" ||
				    cite_type == "citealp" ||
				    cite_type == "citeyearpar")) {
		label = before_str + label;
	}

	if (cite_type == "citep" || cite_type == "citeyearpar" || 
	    (cite_type == "cite" && engine == ENGINE_BASIC) )
		label = op + label + cp;

	return label;
}