// NewPDFGeneratorFromJSON creates a new PDFGenerator and restores all the settings and pages
// from a JSON byte slice which should be created using PDFGenerator.ToJSON().
330881
func NewPDFGeneratorFromJSON(jsonReader io.Reader) (*PDFGenerator, error) {

	jp := new(jsonPDFGenerator)

	err := json.NewDecoder(jsonReader).Decode(jp)
	if err != nil {
		return nil, fmt.Errorf("error unmarshaling JSON: %s", err)
	}

	pdfg, err := NewPDFGenerator()
	if err != nil {
		return nil, fmt.Errorf("error creating PDF generator: %s", err)
	}

	pdfg.TOC = jp.TOC
	pdfg.Cover = jp.Cover
	pdfg.globalOptions = jp.GlobalOptions
	pdfg.outlineOptions = jp.OutlineOptions

	for i, p := range jp.Pages {
		if p.Base64PageData == "" {
			pdfg.AddPage(&Page{
				Input:       p.InputFile,
				PageOptions: p.PageOptions,
			})
			continue
		}
		buf, err := base64.StdEncoding.DecodeString(p.Base64PageData)
		if err != nil {
			return nil, fmt.Errorf("error decoding base 64 input on page %d: %s", i, err)
		}
		pdfg.AddPage(&PageReader{
			Input:       bytes.NewReader(buf),
			PageOptions: p.PageOptions,
		})
	}

	return pdfg, nil
}
848720
func NewGenerator(sections uint) (*Generator, error) {
	if sections%8 != 0 {
		return nil, errors.New("section count not multiple of 8")
	}
	b := &Generator{sections: sections}
	for i := 0; i < types.BloomBitLength; i++ {
		b.blooms[i] = make([]byte, sections/8)
	}
	return b, nil
}
1036589
func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter {
	return &PrettyPrinter{
		w:           w,
		indentStr:   indentStr,
		indentDepth: 0,
	}
}
545480
func NewCodeGenerator(schemas []string) *CodeGenerator {
	return &CodeGenerator{
		rawSchemas:        schemas,
		structs:           make(map[string]*bytes.Buffer),
		codeSnippets:      make([]*bytes.Buffer, 0),
		schemaDefinitions: &bytes.Buffer{},
	}
}
1157429
func NewFromTemplate(r io.Reader) (Generator, error) {
	var config rspec.Spec
	if err := json.NewDecoder(r).Decode(&config); err != nil {
		return Generator{}, err
	}

	envCache := map[string]int{}
	if config.Process != nil {
		envCache = createEnvCacheMap(config.Process.Env)
	}

	return Generator{
		Config: &config,
		envMap: envCache,
	}, nil
}
565189
func NewUniformGenerator(seed int64) *UniformGenerator {
	return &UniformGenerator{mu: new(sync.Mutex), rd: rand.New(rand.NewSource(seed))}
}
955595
func NewHeaderFromJSON(data string) (*Header, error) {
	h := &Header{
		header: new(types.Header),
	}
	if err := json.Unmarshal([]byte(data), h.header); err != nil {
		return nil, err
	}
	return h, nil
}
858360
func NewReaderFuncLoader(rfl ReaderFuncLoader, r io.Reader) Loader {
	return &readerFuncLoader{
		rfl: rfl,
		r:   r,
	}
}
939185
func NewVersionedPrinter(printer ResourcePrinter, convertor runtime.ObjectConvertor, versions ...unversioned.GroupVersion) ResourcePrinter {
	return &VersionedPrinter{
		printer:   printer,
		convertor: convertor,
		versions:  versions,
	}
}
360282
func New() *Generator {
	g := new(Generator)
	g.Buffer = new(bytes.Buffer)
	g.Request = new(plugin.CodeGeneratorRequest)
	g.Response = new(plugin.CodeGeneratorResponse)
	return g
}
286802
func (pdfg *PDFGenerator) AddPage(p page) {
	pdfg.pages = append(pdfg.pages, p)
}
672836
func NewJSONWriter(logger logrus.FieldLogger) *JSONWriter {
	writer := &JSONWriter{logger: logger}

	writer.Reporter = DefaultErrorReporter
	writer.ErrorEnhancer = defaultJSONErrorEnhancer
	return writer
}
582314
func NewGenerator(o *GeneratorOptions) Generator {
	// TODO(abg): Determine package name from `namespace go` directive.
	namespace := NewNamespace()
	return &generator{
		PackageName:    o.PackageName,
		ImportPath:     o.ImportPath,
		Namespace:      namespace,
		importer:       newImporter(namespace.Child()),
		mangler:        newMangler(),
		thriftImporter: o.Importer,
		fset:           token.NewFileSet(),
		noZap:          o.NoZap,
	}
}
1218009
func NewPaperDocRevertType(Description string) *PaperDocRevertType {
	s := new(PaperDocRevertType)
	s.Description = Description
	return s
}
143876
func NewEventGenerator(seed int64) *EventGenerator {
	return &EventGenerator{
		r: rand.New(rand.NewSource(seed)),
		g: gen.NewGenerator(seed + 1),
	}
}
154324
func (f *Fpdf) newLink(x, y, w, h float64, link int, linkStr string) {
	// linkList, ok := f.pageLinks[f.page]
	// if !ok {
	// linkList = make([]linkType, 0, 8)
	// f.pageLinks[f.page] = linkList
	// }
	f.pageLinks[f.page] = append(f.pageLinks[f.page],
		linkType{x * f.k, f.hPt - y*f.k, w * f.k, h * f.k, link, linkStr})
}
711961
func (original Transform) TransformFromJSON(from, to Transform, fncMap template.FuncMap) (string, error) {
	jsonParsed, _ := gabs.ParseJSON([]byte(from))
	ch, _ := jsonParsed.ChildrenMap()
	path := ""
	values := make(map[string]string)
	walkTreeJSON(ch, &path, values)
	oriParsed, _ := gabs.ParseJSON([]byte(original))
	parsedMap := make(map[string]string)
	for k, v := range values {
		parsedMap[cleanString(v)] = cleanString(oriParsed.Path(k).String())
	}
	return generateTransformedMessage(parsedMap, to, fncMap)
}